N Queens
Hardjavapythonccppjavascript
Count the number of distinct ways to place N queens on an N x N chessboard so that no two queens attack each other (no two share a row, column or diagonal).
Input Format
A single line containing the integer N.
Output Format
Print the number of valid arrangements.
Example 1
Input
4
Output
2
Explanation: For a 4x4 board there are exactly two valid arrangements.
- 1 <= N <= 12
Submit an attempt to unlock the solution. (Sign in first.)
Related Problems
- Sudoku SolverHard · java, python, c, cpp, javascriptSolve Problem
- Factorial Using RecursionEasy · java, python, c, cpp, javascriptSolve Problem
- Fibonacci NumberEasy · java, python, c, cpp, javascriptSolve Problem