0
0
DSA Cprogramming~10 mins

N Queens Problem in DSA C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare the chessboard size variable.

DSA C
int [1] = 8;
Drag options to blanks, or click blank then click option'
AN
BboardSize
Csize
Dchessboard
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names that are not standard or clear like 'boardSize' or 'chessboard'.
2fill in blank
medium

Complete the code to initialize the chessboard array with zeros.

DSA C
int board[[1]][[1]] = {0};
Drag options to blanks, or click blank then click option'
AboardSize
B8
Csize
DN
Attempts:
3 left
💡 Hint
Common Mistakes
Using a fixed number like 8 instead of the variable N.
Using undefined variables like 'size' or 'boardSize'.
3fill in blank
hard

Fix the error in the function signature for checking if a queen can be placed.

DSA C
int isSafe(int board[[1]][[1]], int row, int col) {
Drag options to blanks, or click blank then click option'
Asize
BN
C8
DboardSize
Attempts:
3 left
💡 Hint
Common Mistakes
Using a fixed number like 8 instead of the variable N.
Using undefined variables in the parameter.
4fill in blank
hard

Fill both blanks to complete the loop that checks the left side of the current row for queens.

DSA C
for (int i = 0; i [1] col; i[2]) {
    if (board[row][i] == 1) {
        return 0;
    }
}
Drag options to blanks, or click blank then click option'
A<
B>
C++
D--
Attempts:
3 left
💡 Hint
Common Mistakes
Using > instead of < in the loop condition.
Using decrement instead of increment.
5fill in blank
hard

Fill all three blanks to complete the recursive function call and backtracking step.

DSA C
if (solveNQUtil(board, [1])) {
    return 1;
}
board[row][[2]] = [3]; // Backtrack
Drag options to blanks, or click blank then click option'
Acol + 1
Bcol
C0
Attempts:
3 left
💡 Hint
Common Mistakes
Not incrementing the column in the recursive call.
Setting the wrong cell to 0 during backtracking.