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

Function move

javascript/0054-spiral-matrix.js:264–288  ·  view source on GitHub ↗
(
    matrix,
    row,
    col,
    direction,
    changeDirection,
    order,
    VISITED = 101,
)

Source from the content-addressed store, hash-verified

262};
263
264const move = (
265 matrix,
266 row,
267 col,
268 direction,
269 changeDirection,
270 order,
271 VISITED = 101,
272) => {
273 const [rows, cols] = [matrix.length, matrix[0].length];
274
275 while (canMove(matrix, row, rows, col, cols, direction)) {
276 /* Time O(ROWS * COLS) */
277 [row, col] = getCell(row, col, direction);
278
279 order.push(
280 matrix[row][col],
281 ); /* | Ignore Auxilary Spsace O(ROWS * COLS) */
282 matrix[row][col] = VISITED;
283
284 changeDirection = 0;
285 }
286
287 return [row, col, direction, changeDirection];
288};
289
290const canMove = (matrix, row, rows, col, cols, direction) => {
291 if (!isInBounds(row, rows, col, cols, direction)) return false;

Callers 1

getPointersFunction · 0.85

Calls 3

getCellFunction · 0.85
canMoveFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected