Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start the search from the first cell in the grid.
DSA Python
for i in range(len(board)): for j in range(len(board[0])): if board[i][j] == word[[1]]: if backtrack(i, j, 0): return True
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 for the first character index.
Using len(word) which is out of range.
✗ Incorrect
The search starts by matching the first character of the word, which is at index 0.
2fill in blank
mediumComplete the code to check if the current position is out of grid bounds.
DSA Python
if i < 0 or i >= len(board) or j < 0 or j >= [1]: return False
Attempts:
3 left
💡 Hint
Common Mistakes
Using len(board) which is the number of rows.
Using len(word) which is unrelated.
✗ Incorrect
The number of columns is len(board[0]), so j must be less than that to be inside the grid.
3fill in blank
hardFix the error in marking the current cell as visited.
DSA Python
temp = board[i][j] board[i][j] = [1] # backtracking calls here board[i][j] = temp
Attempts:
3 left
💡 Hint
Common Mistakes
Using None which causes type errors.
Using empty string which may cause confusion.
✗ Incorrect
Marking the cell with '#' is a common way to indicate it is visited temporarily.
4fill in blank
hardFill both blanks to check the next character and explore neighbors.
DSA Python
if word[[1]] != board[i][j]: return False return (backtrack(i+1, j, [2]) or backtrack(i-1, j, [2]) or backtrack(i, j+1, [2]) or backtrack(i, j-1, [2]))
Attempts:
3 left
💡 Hint
Common Mistakes
Using index - 1 which goes backward in the word.
Using 0 which restarts the search incorrectly.
✗ Incorrect
We check if the current board cell matches word[index], then explore neighbors with index + 1 for the next character.
5fill in blank
hardFill all three blanks to complete the backtracking function signature and base case.
DSA Python
def backtrack(i, j, [1]): if [2] == len(word): return True if i < 0 or i >= len(board) or j < 0 or j >= len(board[0]) or board[i][j] != word[[3]]: return False
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'word' as parameter instead of index.
Using 'index == 0' as parameter which is a boolean, not a variable.
✗ Incorrect
The function uses 'index' to track the current character position. The base case checks if index equals word length, and the character check uses word[index].
