0
0
DSA Typescriptprogramming~10 mins

Number of Islands BFS and DFS in DSA Typescript - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Acol
Brow
Cgrid
Dvisited
Attempts:
3 left
💡 Hint
Common Mistakes
Pushing only the row index.
Pushing the grid or visited array instead of column.
2fill in blank
medium

Complete 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'
Arow
Bcol
Cgrid
Dqueue
Attempts:
3 left
💡 Hint
Common Mistakes
Marking visited using column index only.
Marking grid or queue instead of visited.
3fill in blank
hard

Fix 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'
A1
B0
C-1
Drow
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 for both row and column changes (no movement).
Using row variable instead of numeric offsets.
4fill in blank
hard

Fill 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'
Adr
Bdc
C-1
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using fixed numbers instead of direction variables.
Not checking boundaries properly.
5fill in blank
hard

Fill 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'
A1
B-1
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using 2 instead of 1 for direction offsets.
Mixing up positive and negative signs.