N-Queens II

Hard

The n-queens puzzle places n queens on an n × n board so that no two attack each other.

Return the number of distinct solutions.

Example 1

totalNQueens()
Input
n = 1
Output
1

Example 2

totalNQueens()
Input
n = 4
Output
2
Constraints
1 <= n <= 9

Topics

BacktrackingRecursion

Implement totalNQueens in the editor and return the answer — printing it is never graded.