Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start BFS from the given cell.
DSA C#
Queue<(int, int)> queue = new Queue<(int, int)>();
queue.[1]((row, col));Attempts:
3 left
💡 Hint
Common Mistakes
Using Add or Push instead of Enqueue.
✗ Incorrect
In C#, the method to add an item to a Queue is Enqueue.
2fill in blank
mediumComplete the code to mark the current cell as visited in the grid.
DSA C#
grid[row][col] = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Marking visited cells as '1' which means land.
✗ Incorrect
We mark visited land cells as '0' to indicate water or visited.
3fill in blank
hardFix the error in the DFS recursive call to explore neighbors.
DSA C#
DFS(grid, row + [1], col); DFS(grid, row, col + [1]); DFS(grid, row - [1], col); DFS(grid, row, col - [1]);
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or 2 as offset causing no movement or skipping cells.
✗ Incorrect
We move one step in each direction, so the offset is 1.
4fill in blank
hardFill both blanks to check if the cell is within grid bounds.
DSA C#
if (row [1] 0 && row [2] grid.Length)
Attempts:
3 left
💡 Hint
Common Mistakes
Using > or <= which can cause index errors.
✗ Incorrect
Row index must be greater or equal to 0 and less than grid length.
5fill in blank
hardFill all three blanks to create a dictionary comprehension for counting islands by size.
DSA C#
var islandSizes = new Dictionary<int, int>(); foreach (var size in sizes) { if (islandSizes.ContainsKey([1])) { islandSizes[[2]] += 1; } else { islandSizes[[3]] = 1; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong keys or values causing runtime errors.
✗ Incorrect
We use the variable size as the key to count occurrences.
