Challenge - 5 Problems
N Queens Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of N Queens Board Representation
What is the printed board state after placing 4 queens in a valid solution for the 4-Queens problem?
DSA Go
package main import "fmt" func printBoard(board [][]int) { for _, row := range board { for _, val := range row { if val == 1 { fmt.Print("Q ") } else { fmt.Print(". ") } } fmt.Println() } } func main() { board := [][]int{ {0, 1, 0, 0}, {0, 0, 0, 1}, {1, 0, 0, 0}, {0, 0, 1, 0}, } printBoard(board) }
Attempts:
2 left
💡 Hint
Look carefully at the positions of 1s in the board array and match them to Q positions.
✗ Incorrect
The board array has 1s at positions (0,1), (1,3), (2,0), and (3,2). This matches option C's printed board.
🧠 Conceptual
intermediateUnderstanding Diagonal Attacks in N Queens
Which of the following conditions correctly checks if two queens at positions (r1, c1) and (r2, c2) are attacking each other diagonally?
Attempts:
2 left
💡 Hint
Diagonal attack means difference in rows equals difference in columns.
✗ Incorrect
Two queens attack diagonally if the absolute difference of their row indices equals the absolute difference of their column indices.
🔧 Debug
advancedIdentify the error in the backtracking function
What error will occur when running this backtracking function snippet for N Queens?
DSA Go
func solveNQueens(row int, board [][]int, n int) bool { if row == n { return true } for col := 0; col < n; col++ { if isSafe(row, col, board, n) { board[row][col] = 1 if solveNQueens(row+1, board, n) { return true } board[row][col] = 0 } } return false } // isSafe function omitted for brevity
Attempts:
2 left
💡 Hint
Check what happens after finding the first solution.
✗ Incorrect
The function returns true immediately after finding the first solution, so it does not explore all possible solutions.
🚀 Application
advancedNumber of solutions for 5-Queens problem
How many distinct solutions exist for the 5-Queens problem?
Attempts:
2 left
💡 Hint
Recall the known counts of solutions for small N.
✗ Incorrect
The 5-Queens problem has exactly 10 distinct solutions.
❓ Predict Output
expertOutput of partial board after placing queens
Given this partial board state after placing queens in a 6x6 board, what is the printed output?
DSA Go
package main import "fmt" func printBoard(board [][]int) { for _, row := range board { for _, val := range row { if val == 1 { fmt.Print("Q ") } else { fmt.Print(". ") } } fmt.Println() } } func main() { board := [][]int{ {0, 0, 1, 0, 0, 0}, {1, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 1, 0}, {0, 1, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0}, {0, 0, 0, 0, 0, 1}, } printBoard(board) }
Attempts:
2 left
💡 Hint
Match the 1s in the board array to Q positions in each row.
✗ Incorrect
The board has queens at (0,2), (1,0), (2,4), (3,1), (4,3), (5,5), matching option B's output.
