Count Nonattacking Queen Configurations

Quick Overview

Count all distinct nonattacking n-queen configurations without returning board layouts or merging symmetric placements.

Count Nonattacking Queen Configurations

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Other

### Problem Count the distinct ways to put `n` queens on an `n` by `n` chessboard with no two in a common row, column, or diagonal. Return the integer count rather than the boards themselves. Configurations with different queen positions are distinct, including different rotations or reflections. ```cpp int totalNQueens(int n); ``` ### Examples ```text Input: n = 3 Output: 0 ``` ```text Input: n = 5 Output: 10 ``` ### Constraints - `1 <= n <= 9`. - A valid configuration contains exactly `n` queens. - Count board configurations, without identifying different symmetric boards as one.

Overview: Count all distinct nonattacking n-queen configurations without returning board layouts or merging symmetric placements.

Meta logo
Meta
Jul 21, 2026
hardSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Count the distinct ways to put n queens on an n by n chessboard with no two in a common row, column, or diagonal. Return the integer count rather than the boards themselves. Configurations with different queen positions are distinct, including different rotations or reflections.

int totalNQueens(int n);

Examples

Input: n = 3
Output: 0
Input: n = 5
Output: 10

Constraints

  • 1 <= n <= 9 .
  • A valid configuration contains exactly n queens.
  • Count board configurations, without identifying different symmetric boards as one.