MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / bfs

Function bfs

javascript/0130-surrounded-regions.js:112–130  ·  view source on GitHub ↗
(board, queue)

Source from the content-addressed store, hash-verified

110};
111
112var bfs = (board, queue) => {
113 const [rows, cols] = [board.length, board[0].length];
114
115 while (!queue.isEmpty()) {
116 for (let i = queue.size() - 1; 0 <= i; i--) {
117 /* Time O(WIDTH) */
118 const [row, col] = queue.dequeue();
119
120 const isBaseCase = board[row][col] !== 'O';
121 if (isBaseCase) continue;
122
123 board[row][col] = '*';
124
125 for (const [_row, _col] of getNeighbors(row, rows, col, cols)) {
126 queue.enqueue([_row, _col]); /* Space O(WIDTH) */
127 }
128 }
129 }
130};
131
132var searchGrid = (board) => {
133 const [rows, cols] = [board.length, board[0].length];

Callers 1

solveFunction · 0.70

Calls 3

getNeighborsFunction · 0.70
isEmptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected