(board, n, colSet, posDiagSet, negDiagSet, row = 0, moves = [])
| 16 | } |
| 17 | |
| 18 | const 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 | |
| 41 | const backTrack = ( |
| 42 | board, |
no test coverage detected