N-Queens II
Return the number of distinct solutions for n queens.
Examples
Input: 4
Output: 2
Input: 1
Output: 1
Hints
Use a recursive backtracking approach to explore all possible queen placements row by row, pruning invalid paths early.
Maintain three sets to track occupied columns and both positive/negative diagonals (using `col + row` and `col - row` as keys) to detect conflicts in O(1) time.
Optimize space by using bitmasking (e.g., integers to represent columns/diagonals) to reduce memory overhead and improve performance for larger `n`.
Related Problems
N-Queens II
Return the number of distinct solutions for n queens.