02.08 · Problem
N-Queens: Count the Boards
Place n queens on an n × n chessboard so that no two attack each other: no two share a row, a column or a diagonal. Return how many ways there are.
Examples
Example 1
Input: n = 4
Output: 2
. Q . . . . Q .
. . . Q Q . . .
Q . . . . . . Q
. . Q . . Q . .solulu Pro
Continue this problem with Pro
Inside: step-by-step hints · 9 hidden tests · reference solutions · code editor.
Lifetime ₹1,999 ₹999 · Launch offer
Item 19 of 44 · updated 2026-10-13