0
0
DSA Pythonprogramming~10 mins

Set Matrix Zeroes In Place in DSA Python - Interactive Practice

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

Complete the code to mark the first row and column if a zero is found.

DSA Python
for i in range(len(matrix)):
    for j in range(len(matrix[0])):
        if matrix[i][j] == [1]:
            matrix[i][0] = 0
            matrix[0][j] = 0
Drag options to blanks, or click blank then click option'
A0
B-1
C1
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 1 instead of 0.
Using None which is not a matrix element.
Using negative numbers which are not relevant here.
2fill in blank
medium

Complete the code to zero out cells based on the first row and column markers.

DSA Python
for i in range(1, len(matrix)):
    for j in range(1, len(matrix[0])):
        if matrix[i][0] == [1] or matrix[0][j] == 0:
            matrix[i][j] = 0
Drag options to blanks, or click blank then click option'
A1
B-1
C0
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 1 instead of 0.
Using None or negative values incorrectly.
3fill in blank
hard

Fix the error in the code that resets the first row to zero if needed.

DSA Python
if first_row_has_zero:
    for j in range(len(matrix[0])):
        matrix[0][j] = [1]
Drag options to blanks, or click blank then click option'
A0
B1
C-1
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Setting to 1 or None instead of zero.
Forgetting to reset the first row.
4fill in blank
hard

Fill both blanks to reset the first column to zero if needed.

DSA Python
if first_col_has_zero:
    for i in range([1]):
        matrix[i][[2]] = 0
Drag options to blanks, or click blank then click option'
Alen(matrix)
Blen(matrix[0])
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using column length instead of row length for loop.
Using wrong column index.
5fill in blank
hard

Fill all three blanks to check if the first row and column have zeros initially.

DSA Python
first_row_has_zero = any(matrix[0][j] == [1] for j in range([2]))
first_col_has_zero = any(matrix[i][[3]] == 0 for i in range(len(matrix)))
Drag options to blanks, or click blank then click option'
A0
Blen(matrix[0])
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong indices for row or column.
Checking for 1 instead of 0.