(heights, queue)
| 190 | }; |
| 191 | |
| 192 | const bfs = (heights, queue) => { |
| 193 | const [rows, cols] = [heights.length, heights[0].length]; |
| 194 | const isReachable = getMatrix( |
| 195 | rows, |
| 196 | cols, |
| 197 | ); /* Time O(ROWS * COLS) | Space O(ROWS * COLS) */ |
| 198 | |
| 199 | while (!queue.isEmpty()) { |
| 200 | for (let i = queue.size() - 1; 0 <= i; i--) { |
| 201 | /* | Space O(WIDTH) */ |
| 202 | const [row, col] = queue.dequeue(); |
| 203 | |
| 204 | checkNeighbor(heights, row, rows, col, cols, isReachable, queue); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | return isReachable; |
| 209 | }; |
| 210 | |
| 211 | var getMatrix = (rows, cols) => |
| 212 | new Array(rows) |
no test coverage detected