Try to solve the N-Queens problem.


Given a chessboard of size n×nn \times n, determine how many ways nn queens can be placed on the board, such that no two queens attack each other.

A queen can move horizontally, vertically, and diagonally on a chessboard. One queen can be attacked by another queen if both share the same row, column, or diagonal.


  • 1n91 \leq n \leq 9


Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy