Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the chessboard with empty cells represented by '.'
DSA Python
board = [['.' for _ in range([1])] for _ in range([1])]
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable not defined for board size.
Using different variables for rows and columns.
✗ Incorrect
The board size is n x n, so we use 'n' to create rows and columns.
2fill in blank
mediumComplete the code to check if a queen can be placed at row r and column c without conflicts.
DSA Python
for i in range(r): if board[i][c] == 'Q': return [1]
Attempts:
3 left
💡 Hint
Common Mistakes
Returning True when conflict is found.
Returning None or 0 which do not indicate failure clearly.
✗ Incorrect
If there is already a queen in the same column above, we cannot place another queen there, so return False.
3fill in blank
hardFix the error in the diagonal check to correctly detect conflicts for the upper left diagonal.
DSA Python
i, j = r, c while i >= 0 and j >= 0: if board[i][j] == 'Q': return [1] i -= 1 j -= 1
Attempts:
3 left
💡 Hint
Common Mistakes
Returning True instead of False on conflict.
Not decrementing i and j correctly.
✗ Incorrect
If a queen is found on the upper left diagonal, placement is invalid, so return False.
4fill in blank
hardFill both blanks to check the upper right diagonal for conflicts.
DSA Python
i, j = r, c while i >= 0 and j [1] n: if board[i][j] == 'Q': return [2] i -= 1 j += 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' for the column boundary.
Returning True instead of False on conflict.
✗ Incorrect
We check while j is less than n to stay inside the board, and return False if a queen is found.
5fill in blank
hardFill all three blanks to place a queen, recurse to next row, and backtrack by removing the queen.
DSA Python
board[r][c] = [1] if solve(r [2] 1): return True board[r][c] = [3]
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong symbols for queen or empty cell.
Using '-' instead of '.' to clear the cell.
Using subtraction instead of addition for next row.
✗ Incorrect
Place 'Q' to mark queen, move to next row with r + 1, and remove queen by resetting to '.' on backtrack.
