Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the current cell matches the current character of the word.
DSA Rust
if board[row][col] == word.chars().nth([1]).unwrap() {
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable that is not defined or not the index for the word characters.
✗ Incorrect
The variable 'i' is commonly used as the index for the current character in the word during backtracking.
2fill in blank
mediumComplete the code to mark the current cell as visited by replacing its character.
DSA Rust
let temp = board[row][col];
board[row][col] = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Using a character that might appear in the board and cause incorrect matches.
✗ Incorrect
Using '#' is a common way to mark a cell as visited temporarily in backtracking.
3fill in blank
hardFix the error in the recursive call to explore neighbors in four directions.
DSA Rust
let found = dfs(board, word, row + [1], col, i + 1) || dfs(board, word, row, col + [2], i + 1) || dfs(board, word, row - [3], col, i + 1) || dfs(board, word, row, col - 1, i + 1);
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong increments or decrements for row and col in recursive calls.
✗ Incorrect
To move down, add 1 to row; to move right, add 1 to col; to move up, subtract 1 from row; to move left, subtract 1 from col.
4fill in blank
hardFill both blanks to restore the original character after backtracking and return the result.
DSA Rust
board[row][col] = [1]; return [2];
Attempts:
3 left
💡 Hint
Common Mistakes
Not restoring the cell, causing incorrect future matches.
Returning a wrong boolean value.
✗ Incorrect
We restore the cell to its original character stored in 'temp' and return whether the word was found in 'found'.
5fill in blank
hardFill all three blanks to complete the main function that starts the search for the word in the grid.
DSA Rust
for row in 0..[1] { for col in 0..[2] { if dfs(&mut board, &word, row, col, 0) == [3] { return true; } } } return false;
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong loop bounds causing index errors.
Returning false instead of true when word is found.
✗ Incorrect
We loop over all rows and columns using board dimensions and return true if dfs finds the word.
