FastPrepN-Queens Solution Count

N-Queens Solution Count

Optimus Information logoOptimus Information● HardINTERNONSITE INTERVIEW
Learn

Problem statement

Place n queens on an n x n chessboard so no two attack one another. Return the number of distinct valid placements.

Function

totalNQueens(n: int) → int

Examples

Example 1

n = 4return = 2

A four-by-four board has two solutions.

Example 2

n = 1return = 1

The single square accepts one queen.

Constraints

  • 1 <= n <= 14.

Source note: Author-written prompt excerpt retained for source fidelity.

More Optimus Information problems

See Optimus Information hiring insights
public int totalNQueens(int n) {
    // Write your code here.
}
n4
expected2
Checking account…