Bird
0
0
DSA Cprogramming~10 mins

Set Matrix Zeroes In Place in DSA C - Interactive Practice

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

Complete 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'
A1
B-1
C0
Dmatrix[i][j]
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.
2fill in blank
medium

Complete 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'
A1
B0
Cmatrix[i][j]
D-1
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.
3fill in blank
hard

Fix 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'
A<=
B>=
C>
D<
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.
4fill in blank
hard

Fill 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'
A<
B<=
C>
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' causing index out of range.
Using '>' or '>=' which are invalid for forward loops.
5fill in blank
hard

Fill 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'
A<
B0
C==
D<=
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.