Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create an empty chessboard of size n x n filled with '.'
DSA Rust
let mut board = vec![vec!['.'; [1]]; n];
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or 1 instead of n for the size of the board.
Using n+1 which creates an extra column.
✗ Incorrect
We need to create a board with n rows and n columns, so the inner vector length must be n.
2fill in blank
mediumComplete the code to check if a queen can be placed at (row, col) without conflicts.
DSA Rust
for i in 0..row { if board[i][col] == 'Q' || board[i][col [1] (row - i)] == 'Q' || board[i][col [2] (i - row)] == 'Q' { return false; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication or division which are incorrect here.
Using subtraction for both diagonals.
✗ Incorrect
To check diagonals, we add or subtract the difference between rows and columns. Here, we add to check the right diagonal and subtract for the left diagonal.
3fill in blank
hardFix the error in the recursive function call to solve the N Queens problem.
DSA Rust
if solve(board, row [1] 1, n) { return true; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction which goes to the previous row.
Using multiplication or division which are invalid here.
✗ Incorrect
We move to the next row by adding 1 to the current row index.
4fill in blank
hardFill both blanks to place a queen and then remove it (backtracking).
DSA Rust
board[row][col] = [1]; // recursive call board[row][col] = [2];
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong characters like 'X' or 'O' for queens or empty spots.
Not resetting the spot after backtracking.
✗ Incorrect
We place a queen with 'Q' and remove it by resetting to '.' during backtracking.
5fill in blank
hardFill all three blanks to collect the current board state as a vector of strings.
DSA Rust
let mut current = Vec::new(); for r in 0..n { let row_str = board[r].iter().[1](|&c| c).[2]::<String>(); current.[3](row_str); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter instead of map which filters elements.
Using push on iterator which is invalid.
✗ Incorrect
We use map to dereference each &char to char, collect::() to build the string from chars, and push to add the string to the current vector.
