Trains the technique from
LeetCode 52N-Queens IIThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A square yard is laid out as n rows by n columns. A beacon placed in a cell sweeps its whole row, its whole column, and both diagonals running through it, for any distance.
Place n beacons on the yard so that no beacon stands in another's sweep. Return how many arrangements manage it.
Example 1
On a two-by-two yard any two cells share a row, a column or a diagonal, so nothing works.
Example 2
Four arrangements fit on a six-by-six yard, and each is a turn or a mirror image of the others.
Example 3
Three hundred and fifty-two arrangements fit on a nine-by-nine yard.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def total_n_queens(n: int) -> int:public int totalNQueens(int n)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.