MCPcopy Index your code
hub / github.com/neetcode-gh/leetcode / dfs

Function dfs

javascript/0051-n-queens.js:18–39  ·  view source on GitHub ↗
(board, n, colSet, posDiagSet, negDiagSet, row = 0, moves = [])

Source from the content-addressed store, hash-verified

16}
17
18const dfs = (board, n, colSet, posDiagSet, negDiagSet, row = 0, moves = []) => {
19 const isBaseCase = row === n;
20 if (isBaseCase) {
21 const rows = board.map((_row) => _row.join(''));
22
23 moves.push(rows);
24
25 return moves;
26 }
27
28 for (let col = 0; col < n; col++) {
29 const hasQueen =
30 colSet.has(col) ||
31 posDiagSet.has(row + col) ||
32 negDiagSet.has(row - col);
33 if (hasQueen) continue;
34
35 backTrack(board, n, row, col, colSet, posDiagSet, negDiagSet, moves);
36 }
37
38 return moves;
39};
40
41const backTrack = (
42 board,

Callers 2

solveNQueensFunction · 0.70
backTrackFunction · 0.70

Calls 2

backTrackFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected