MCPcopy Create free account
hub / github.com/betomoedano/JavaScript-Coding-Interview-Questions / riverSizes

Function riverSizes

graphs/riverSizes.js:48–59  ·  view source on GitHub ↗
(matrix)

Source from the content-addressed store, hash-verified

46// O(wh) time | O(wh) space
47
48function riverSizes(matrix) {
49 const sizes = [];
50 const visited = matrix.map((row) => row.map((value) => false));
51
52 for (let row = 0; row < matrix.length; row++) {
53 for (let col = 0; col < matrix[row].length; col++) {
54 if (visited[row][col]) continue;
55 traverseNode(row, col, matrix, visited, sizes);
56 }
57 }
58 return sizes;
59}
60
61function traverseNode(row, col, matrix, visited, sizes) {
62 let currentRiverSize = 0;

Callers

nothing calls this directly

Calls 1

traverseNodeFunction · 0.85

Tested by

no test coverage detected