Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start BFS from the current cell.
DSA C++
queue<pair<int, int>> q;
q.push([1]);Attempts:
3 left
💡 Hint
Common Mistakes
Swapping i and j coordinates.
Pushing incorrect or fixed coordinates like (0,0).
✗ Incorrect
We push the current cell coordinates (i, j) into the queue to start BFS.
2fill in blank
mediumComplete the code to mark the current cell as visited.
DSA C++
grid[[1]][j] = '0';
Attempts:
3 left
💡 Hint
Common Mistakes
Using column index instead of row index.
Using a variable that does not exist.
✗ Incorrect
We mark the current cell at row i and column j as '0' to indicate it is visited.
3fill in blank
hardFix the error in the DFS recursive call to explore neighbors.
DSA C++
if (row >= 0 && row < m && col >= 0 && col < n && grid[row][col] == '1') { [1](grid, row, col); }
Attempts:
3 left
💡 Hint
Common Mistakes
Calling BFS inside DFS.
Using undefined function names.
✗ Incorrect
The DFS function calls itself recursively to explore neighbors.
4fill in blank
hardFill both blanks to check all four directions in BFS.
DSA C++
int directions[4][2] = {{-1, 0}, {1, 0}, [1], [2];
Attempts:
3 left
💡 Hint
Common Mistakes
Using diagonal directions instead of left/right.
Swapping row and column changes.
✗ Incorrect
The four directions are up (-1,0), down (1,0), left (0,-1), and right (0,1).
5fill in blank
hardFill all three blanks to complete the DFS function signature and base case.
DSA C++
void [1](vector<vector<char>>& grid, int [2], int [3]) { int m = grid.size(); int n = grid[0].size(); if ([2] < 0 || [2] >= m || [3] < 0 || [3] >= n || grid[[2]][[3]] == '0') return; grid[[2]][[3]] = '0'; // explore neighbors }
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong function names.
Using incorrect parameter names.
✗ Incorrect
The DFS function is named 'dfs' and uses 'row' and 'col' as parameters for coordinates.
