← All problems

N-Queens II (count)

Hard dynamic programmingbacktracking LeetCode ↗
Count the number of distinct ways to place n queens on an n x n chessboard so that no two queens attack each other. Return the count, not the boards themselves.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(n!), Space O(n)

Common pitfalls

  • Diagonal collision detection wrong
  • Counting symmetric duplicates separately is fine

Your solution

Log in to save your code and track progress.