MCPcopy Create free account
hub / github.com/ByteByteGoHq/coding-interview-patterns / nQueens

Function nQueens

cpp/Backtracking/n_queens.cpp:3–10  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1#include <set>
2
3int nQueens(int n) {
4 int res = 0;
5 std::set<int> diagonalsSet;
6 std::set<int> antiDiagonalsSet;
7 std::set<int> colsSet;
8 dfs(0, diagonalsSet, antiDiagonalsSet, colsSet, n, res);
9 return res;
10}
11
12void dfs(int r, std::set<int>& diagonalsSet, std::set<int>& antiDiagonalsSet, std::set<int>& colsSet, int n, int& res) {
13 // Termination condition: If we have reached the end of the rows,

Callers

nothing calls this directly

Calls 1

dfsFunction · 0.70

Tested by

no test coverage detected