Z46

N-Queens Board Placement

Mid / Senior Engineer
Target Time: 25 - 35 Minutes
Type: ARRAY

Problem Statement & Objective

The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other. Return all distinct solutions.

Function Signature (Python)

nqueens_board_placement(n: int) -> list[list[str]]

Input & Output Contract

Output Rule:Sözlük sırasında tahta listesi. Her tahta n adet uzunluğu n olan string. Çözüm yoksa []. Doğru tahtalar yanlış sıradaysa cevap reddedilir.

System Constraints

1 <= n <= 9

Example Execution Walkthrough

n = 4 -> 2 çözüm, sözlük sırasında:
[
 ["..Q.","Q...","...Q",".Q.."],
 [".Q..","...Q","Q...","..Q."]
]
Sütun sırasıyla üretilen ilk tahta ikinci sırada durur. Sıralamadan dönülürse test reddeder.

Example Test Scenarios (3)

Example 1: n=4
Input:[4]
Expected Output:[["..Q.","Q...","...Q",".Q.."],[".Q..","...Q","Q...","..Q."]]
Example 2: n=1
Input:[1]
Expected Output:[["Q"]]
Example 3: n=2 Çözüm Yok
Input:[2]
Expected Output:[]
Loading Python Editor...
Input Parameters
[
  4
]
Expected Output
[
  [
    "..Q.",
    "Q...",
    "...Q",
    ".Q.."
  ],
  [
    ".Q..",
    "...Q",
    "Q...",
    "..Q."
  ]
]