N Queens

Learn about the classic n queens problem and its solution using backtracking.

Introduction to backtracking

The prototypical backtracking problem is the classical nn queens problem, first proposed by German chess enthusiast Max Bezzel in 1848 (under his pseudonym “Schachfreund”) for the standard 8 × 8 board and by François-Joseph Eustache Lionnet in 1869 for the more general n×nn × n board. The problem is to place nn queens on an n×nn × n chessboard so that no two queens are attacking each other. For readers not familiar with the rules of chess, this means that no two queens are in the same row, the same column, or the same diagonal.

Create a free account to access the full course.

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