A royal court places n guards, each moving like a chess queen (any number of squares along a row, column, or diagonal), on an n-by-n board. A placement is safe if no two guards can attack each other: no two share a row, a column, or a diagonal.
Count how many distinct safe placements of exactly n guards exist on the board.
A single line: the integer n.
A single integer: the number of safe placements.
Example 1
Input
4
Expected
2
Explanation
On a 4x4 board there are exactly two safe placements.
Example 2
Input
1
Expected
1
Explanation
On a 1x1 board the single guard has one safe placement.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →