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 Typescript
if (board[row][col] === [1]) {
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using word[0] instead of word[index]
Comparing with the whole word instead of a single 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.
DSA Typescript
visited[row][col] = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Marking visited as false instead of true
Not marking visited at all
✗ Incorrect
We mark the cell as visited by setting visited[row][col] to true.
3fill in blank
hardFix the error in the recursive call to explore neighbors by filling the correct row offset.
DSA Typescript
if (dfs(board, word, row + [1], col, index + 1, visited)) {
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 does not move to a neighbor
Using index instead of a row offset
✗ Incorrect
To move down, we add 1 to the row index.
4fill in blank
hardFill both blanks to check boundaries and if the cell is already visited.
DSA Typescript
if (row < 0 || row >= board.length || col < 0 || col >= board[0].length || visited[[1]][[2]]) { return false; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using index or word instead of row and col
Checking visited outside the board boundaries
✗ Incorrect
We check if the cell at visited[row][col] is already visited.
5fill in blank
hardFill all three blanks to explore all four directions (up, down, left, right) in the DFS.
DSA Typescript
return dfs(board, word, row + [1], col + [2], index + 1, visited) || dfs(board, word, row + [3], col, index + 1, visited) || dfs(board, word, row, col + 1, index + 1, visited) || dfs(board, word, row, col - 1, index + 1, visited);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing row and column offsets
Using index instead of numeric offsets
✗ Incorrect
We move down (row + 1), up (row - 1), right (col + 1), and left (col - 1). Here blanks correspond to row offset for down (1), col offset for left/right (0), and row offset for up (-1).