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

Function solveNQueens

javascript/0051-n-queens.js:7–16  ·  view source on GitHub ↗

* https://leetcode.com/problems/n-queens/ * Time O(N!) | Space O(N^2) * @param {number} n * @return {string[][]}

(
    n,
    colSet = new Set(),
    posDiagSet = new Set(),
    negDiagSet = new Set(),
)

Source from the content-addressed store, hash-verified

5 * @return {string[][]}
6 */
7function solveNQueens(
8 n,
9 colSet = new Set(),
10 posDiagSet = new Set(),
11 negDiagSet = new Set(),
12) {
13 const board = new Array(n).fill().map(() => new Array(n).fill('.'));
14
15 return dfs(board, n, colSet, posDiagSet, negDiagSet);
16}
17
18const dfs = (board, n, colSet, posDiagSet, negDiagSet, row = 0, moves = []) => {
19 const isBaseCase = row === n;

Callers

nothing calls this directly

Calls 1

dfsFunction · 0.70

Tested by

no test coverage detected