CJCoding With Joseph
15free / daySign inCreate account

Queen Safety Check

In the N-Queens puzzle the queens placed so far are stored as a list queens where queens[r] is the column of the queen in row r, one queen per row from the top. Write is_safe(queens: list[int], row: int, col: int) -> bool that returns True when a new queen at (row, col) is attacked by none of the queens in the rows above: for every earlier row r with column c, the new square is unsafe when c equals col (same column) or when the row distance row - r equals col - c or c - col (a diagonal). Rows never clash because each row holds one queen. Do NOT write a main block or any top-level test code; the tests construct the calls. Input: three lines, the columns of the queens already placed (possibly empty), the row and the column to test; the tests print the boolean your function returns.

Expected Output:

True

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Data Structures & Algorithms
📥 Auto-Input:
1 3\n2\n0\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.