Question bank › Backtracking
Dsa Backtracking Hard

N-Queens Threat Assessment

In the game of chess, the N-Queens problem is a famous problem where you have to place N queens on an N x N chessboard such that no two queens threaten each other. However, the twist is that for this task, you need to evaluate the threat levels of different placements of queens. You will provide a list of placements, and for each placement, you need to find how many queens are threatened by others. If no queens threaten each other, print "Safe". If there are threatened queens, print their 1-based indices. Input Format: - The first line contains the integer `n` (1 ≤ n ≤ 15). - The second line contains n space-separated integers corresponding to the column indices (1-based) where queens are placed in each row (1 ≤ column ≤ n). Output Format: - Print the indices of threatened queens or "Safe" if none are threatened. Example: Input: 4 1 3 2 4 Output: 2 3

Key concepts

backtrackingn-queenschess

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.