Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Solve the N-Queens problem for a given board size `n`.

Hard

Problem Statement

Solve the N-Queens problem for a given board size n.

Sample Input

n = 4

Sample Output

. Q . . 
. . . Q 
Q . . . 
. . Q . 

. . Q . 
Q . . . 
. . . Q 
. Q . . 

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
def n_queens(n) # Your code here end
Log in or sign up to run or submit your code.Log inSign up
Input
n = 4
Expected Output
. Q . . 
. . . Q 
Q . . . 
. . Q . 

. . Q . 
Q . . . 
. . . Q 
. Q . .