class Queens { int count=0; void solve(int n, int row, int col, int ld, int rd ){ if(row ==n ){ ++count; return ; } int available = ((1<<n) -1) & ~( col | ld | rd); while (available) { int pos = available & -available; available -= pos; solve(n, row+1, col | pos, (ld | pos) <<1, (rd | pos)>>1); } } public: int nQueens(int n) { // write code here solve(n, 0, 0, 0, 0); return count; } };