Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start BFS from the given cell.
DSA Typescript
queue.push([row, [1]]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Pushing only the row index.
Pushing the grid or visited array instead of column.
✗ Incorrect
We push the current cell's column index along with the row to the queue to start BFS.
2fill in blank
mediumComplete the code to mark the current cell as visited.
DSA Typescript
visited[[1]][col] = true; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Marking visited using column index only.
Marking grid or queue instead of visited.
✗ Incorrect
We mark the current row and column as visited to avoid revisiting.
3fill in blank
hardFix the error in the DFS recursive call to explore neighbors.
DSA Typescript
dfs(grid, row + [1], col + [2], visited);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 for both row and column changes (no movement).
Using row variable instead of numeric offsets.
✗ Incorrect
To explore neighbors, we add or subtract 1 from row or column. Here, row is decreased by 1 and column stays the same.
4fill in blank
hardFill both blanks to check if the neighbor cell is valid and unvisited.
DSA Typescript
if (row + [1] >= 0 && row + [1] < grid.length && col + [2] >= 0 && col + [2] < grid[0].length && !visited[row + [1]][col + [2]] && grid[row + [1]][col + [2]] === '1') {
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using fixed numbers instead of direction variables.
Not checking boundaries properly.
✗ Incorrect
We use dr and dc as row and column direction offsets to check neighbors.
5fill in blank
hardFill all three blanks to create a loop over all four directions for BFS.
DSA Typescript
const directions = [[[1], 0], [[2], 0], [0, [3]], [0, -[3]]];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 2 instead of 1 for direction offsets.
Mixing up positive and negative signs.
✗ Incorrect
Directions represent up (1,0), down (-1,0), right (0,1), left (0,-1) moves.