463. Island Perimeter Flashcards

1
Q

Can you set up variables adjacentSides and landCount?

A

let adjacentSides = 0, landCount = 0;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Can you loop through grid array?

A

for (let i = 0; i < grid.length; i++) {
for (let j = 0; j < grid[i].length; j++) {

    }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

In the looping, can you set up variable points to current cell?

A

for (let i = 0; i < grid.length; i++) {
for (let j = 0; j < grid[i].length; j++) {
let curr = grid[i][j;
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In the looping, can you set up variable points to the top of the current cell?

A

for (let i = 0; i < grid.length; i++) {
for (let j = 0; j < grid[i].length; j++) {
let curr = grid[i][j;
let top = i > 0 ? grid[i - 1][j] : undefined;
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In the looping, can you set up variable points to the left of the current cell?

A

for (let i = 0; i < grid.length; i++) {
for (let j = 0; j < grid[i].length; j++) {
let curr = grid[i][j;
let top = i > 0 ? grid[i - 1][j] : undefined;
let left = j > 0 ? grid[i][j - 1] : undefined;
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When current cell value is 1, can you increase the landCount?

A

for (let i = 0; i < grid.length; i++) {
for (let j = 0; j < grid[i].length; j++) {
let curr = grid[i][j;
let top = i > 0 ? grid[i - 1][j] : undefined;
let left = j > 0 ? grid[i][j - 1] : undefined;
if (curr === 1) {
landCount++;
}
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When current cell value is 1 and left cell value is 1, can you increase the adjacentSides?

A

for (let i = 0; i < grid.length; i++) {
for (let j = 0; j < grid[i].length; j++) {
let curr = grid[i][j;
let top = i > 0 ? grid[i - 1][j] : undefined;
let left = j > 0 ? grid[i][j - 1] : undefined;
if (curr === 1) {
landCount++;
if (left === 1) conSides++;
}
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

When current cell value is 1 and top cell value is 1, can you increase the adjacentSides?

A

for (let i = 0; i < grid.length; i++) {
for (let j = 0; j < grid[i].length; j++) {
let curr = grid[i][j;
let top = i > 0 ? grid[i - 1][j] : undefined;
let left = j > 0 ? grid[i][j - 1] : undefined;
if (curr === 1) {
landCount++;
if (left === 1) conSides++;
if (top === 1) conSides++;
}
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Can you return the result base on landCount and adjacentSides?

A

return landCount * 4 - conSides * 2;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly