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 C
if (board[row][col] == [1]) { // proceed with backtracking }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with word[0] always checks only the first character.
Using '*' or '\0' does not check the correct character.
✗ Incorrect
We compare the board cell with the current character of the word at position index.
2fill in blank
mediumComplete the code to mark the current cell as visited by replacing it with a special character.
DSA C
char temp = board[row][col];
board[row][col] = [1];
// backtracking calls
board[row][col] = temp; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '\0' can cause string termination issues.
Using ' ' (space) might be confusing if spaces are in the grid.
✗ Incorrect
We mark the cell as visited by replacing it with '*', a character not in the word.
3fill in blank
hardFix the error in the recursive call to explore the next character in the word.
DSA C
if (backtrack(board, word, row + 1, col, [1], rows, cols) || backtrack(board, word, row - 1, col, [1], rows, cols) || backtrack(board, word, row, col + 1, [1], rows, cols) || backtrack(board, word, row, col - 1, [1], rows, cols)) { return 1; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using index without increment causes infinite loops.
Decrementing index goes backward in the word.
✗ Incorrect
We move to the next character in the word by increasing index by 1.
4fill in blank
hardFill both blanks to check if the current position is out of bounds or the cell is already visited.
DSA C
if (row [1] 0 || row [2] rows || col < 0 || col >= cols || board[row][col] == '*') { return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' for lower bound allows -1 which is invalid.
Using '>' for upper bound misses the last valid index.
✗ Incorrect
We check if row is less than 0 or greater or equal to rows to stay inside the grid.
5fill in blank
hardFill all three blanks to complete the main function that starts the search for the word in the grid.
DSA C
int exist(char** board, int boardSize, int* boardColSize, char* word) {
for (int i = 0; i < boardSize; i++) {
for (int j = 0; j < [1]; j++) {
if (backtrack(board, word, i, j, 0, boardSize, [2])) {
return [3];
}
}
}
return 0;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using boardSize for columns is incorrect.
Returning 0 inside the loop misses found words.
✗ Incorrect
We use boardColSize[0] to get the number of columns, and return 1 if word is found.