dsa · hard
N Queens II
Return how many ways you can place n queens on an n × n board so that no two share a row, a column, or a diagonal. You do not need the drawings, only the count.
Arguments
n— board size and number of queens to place
Example
n = 4 has 2 placements (the two drawings of the companion board problem).
n = 1 → 1. n = 2 and n = 3 → 0.
Constraints
1 <= n <= 9
Examples
Example 1
Input: 4 Expected: 2
Example 2
Input: 1 Expected: 1