Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to set the first element of the row to zero when a zero is found.
DSA C
if(matrix[i][j] == 0) { matrix[i][0] = [1]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting matrix[i][0] to 1 instead of 0.
Using matrix[i][j] which is already zero, but not marking the row properly.
✗ Incorrect
We mark the first element of the row as zero to indicate that the entire row should be zeroed later.
2fill in blank
mediumComplete the code to set the first element of the column to zero when a zero is found.
DSA C
if(matrix[i][j] == 0) { matrix[0][j] = [1]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting matrix[0][j] to 1 instead of 0.
Using matrix[i][j] which is already zero, but not marking the column properly.
✗ Incorrect
We mark the first element of the column as zero to indicate that the entire column should be zeroed later.
3fill in blank
hardFix the error in the loop condition to avoid overwriting the first row and column prematurely.
DSA C
for(int i = 1; i [1] rows; i++) { for(int j = 1; j < cols; j++) { if(matrix[i][0] == 0 || matrix[0][j] == 0) { matrix[i][j] = 0; } } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' causing index out of range or overwriting first row/column.
Using '>' or '>=' which are incorrect for forward iteration.
✗ Incorrect
We start from 1 and go up to less than rows to avoid modifying the first row and column prematurely.
4fill in blank
hardFill both blanks to correctly zero out the first row and first column if needed.
DSA C
if(firstRowZero) { for(int j = 0; j [1] cols; j++) { matrix[0][j] = 0; } } if(firstColZero) { for(int i = 0; i [2] rows; i++) { matrix[i][0] = 0; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' causing index out of range.
Using '>' or '>=' which are invalid for forward loops.
✗ Incorrect
We use '<' to iterate from 0 up to but not including the length to avoid out-of-bounds errors.
5fill in blank
hardFill all three blanks to correctly check and mark if the first row and first column contain zero.
DSA C
bool firstRowZero = false; bool firstColZero = false; for(int j = 0; j [1] cols; j++) { if(matrix[0][j] == [2]) { firstRowZero = true; break; } } for(int i = 0; i [3] rows; i++) { if(matrix[i][0] == 0) { firstColZero = true; break; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' causing out-of-bound errors.
Using '=' instead of '==' for comparison.
Checking for non-zero values instead of zero.
✗ Incorrect
We loop with '<' to stay in bounds, and check if the element equals zero to mark the flags.
