Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the current cell matches the first letter of the word.
DSA Javascript
if (board[row][col] === word[[1]]) {
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 1 instead of 0 causes skipping the first letter.
Using word.length causes out-of-bound error.
✗ Incorrect
The search starts by matching the first letter of the word, which is at index 0.
2fill in blank
mediumComplete the code to mark the current cell as visited during backtracking.
DSA Javascript
board[row][col] = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Setting cell to null or empty string may cause confusion with valid letters.
Not marking visited cells leads to infinite loops.
✗ Incorrect
Marking the cell with '#' prevents revisiting it during the current search path.
3fill in blank
hardFix the error in the recursive call to search the next letter in all 4 directions.
DSA Javascript
return dfs(board, word, row + [1], col) || dfs(board, word, row - [2], col) || dfs(board, word, row, col + 1) || dfs(board, word, row, col - 1);
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or 2 causes no movement or skipping cells.
Using negative values incorrectly swaps directions.
✗ Incorrect
To move down, add 1 to row; to move up, subtract 1 from row. The first blank needs 1 and the second blank needs -1 respectively.
4fill in blank
hardFill both blanks to restore the original letter after backtracking and to check boundary conditions.
DSA Javascript
board[row][col] = [1]; if (row < 0 || row >= board.length || col < 0 || col >= [2]) return false;
Attempts:
3 left
💡 Hint
Common Mistakes
Restoring with wrong letter causes incorrect board state.
Using board.length for columns causes index errors.
✗ Incorrect
Restore the original letter from word[index]. The column boundary is board[0].length.
5fill in blank
hardFill all three blanks to complete the main function that starts the search for the word in the grid.
DSA Javascript
for (let row = 0; row < [1]; row++) { for (let col = 0; col < [2]; col++) { if (dfs(board, word, row, col, [3])) return true; } } return false;
Attempts:
3 left
💡 Hint
Common Mistakes
Using word length for loops causes index errors.
Starting dfs with wrong index skips letters.
✗ Incorrect
Loop rows with board.length, columns with board[0].length, and start dfs with index 0 of the word.
