Skip to content

Commit 81888b2

Browse files
committed
🔈 [417] Logging ...
1 parent d61fc57 commit 81888b2

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

417/gpt_solution.js

+47-3
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,59 @@ const pacificAtlantic = (heights) => {
1818
const pacificVisited = Array.from({ length: m }, () => new Array(n).fill(false));
1919
const atlanticVisited = Array.from({ length: m }, () => new Array(n).fill(false));
2020

21+
// console.log("pacificVisited")
22+
// console.log(pacificVisited)
23+
// console.log("atlanticVisited")
24+
// console.log(atlanticVisited)
25+
2126
// Add border cells to the respective queues and mark them as visited
2227
for (let i = 0; i < m; i++) {
2328
pacificQueue.push([i, 0]);
2429
atlanticQueue.push([i, n - 1]);
2530
pacificVisited[i][0] = true;
2631
atlanticVisited[i][n - 1] = true;
2732
}
33+
2834
for (let j = 0; j < n; j++) {
2935
pacificQueue.push([0, j]);
3036
atlanticQueue.push([m - 1, j]);
3137
pacificVisited[0][j] = true;
3238
atlanticVisited[m - 1][j] = true;
3339
}
3440

41+
// NOTE: Form grids that wraps the sides that touch the ocean
42+
console.log("pacificVisited")
43+
console.log(pacificVisited)
44+
console.log("pacificQueue")
45+
console.log(pacificQueue)
46+
47+
console.log("atlanticVisited")
48+
console.log(atlanticVisited)
49+
console.log("atlanticQueue")
50+
console.log(atlanticQueue)
51+
3552
// Perform BFS from the Pacific Ocean
3653
bfs(pacificQueue, pacificVisited, heights);
3754

3855
// Perform BFS from the Atlantic Ocean
3956
bfs(atlanticQueue, atlanticVisited, heights);
4057

58+
console.log("-----> After BFS")
59+
console.log("pacificVisited")
60+
console.log(pacificVisited)
61+
console.log("pacificQueue")
62+
console.log(pacificQueue)
63+
64+
console.log("atlanticVisited")
65+
console.log(atlanticVisited)
66+
console.log("atlanticQueue")
67+
console.log(atlanticQueue)
68+
4169
// Find cells that can flow to both oceans
4270
const result = [];
4371
for (let i = 0; i < m; i++) {
4472
for (let j = 0; j < n; j++) {
45-
if (pacificVisited[i][j] && atlanticVisited[i][j]) {
46-
result.push([i, j]);
47-
}
73+
if (pacificVisited[i][j] && atlanticVisited[i][j]) result.push([i, j]);
4874
}
4975
}
5076

@@ -74,3 +100,21 @@ const bfs = (queue, visited, heights) => {
74100
}
75101
}
76102
};
103+
104+
// let x = pacificAtlantic([
105+
// [1, 2, 3],
106+
// [6, 5, 4],
107+
// [2, 7, 2],
108+
// ]);
109+
110+
let x = pacificAtlantic([
111+
[1, 2, 2, 3, 5],
112+
[3, 2, 3, 4, 4],
113+
[2, 4, 5, 3, 1],
114+
[6, 7, 1, 4, 5],
115+
[5, 1, 1, 2, 4]
116+
]);
117+
118+
// let x = pacificAtlantic([[1]]);
119+
console.log("Result");
120+
console.log(x);

0 commit comments

Comments
 (0)