Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
We check if the current element is zero to mark its row and column for zeroing later.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 1 instead of 0.
Using None or negative values incorrectly.
✗ Incorrect
If either the row or column is marked zero, set the cell to zero.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting to 1 or None instead of zero.
Forgetting to reset the first row.
✗ Incorrect
We set all elements in the first row to zero if the first row originally had any zero.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using column length instead of row length for loop.
Using wrong column index.
✗ Incorrect
We loop over all rows (len(matrix)) and set the first column (index 0) to zero.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong indices for row or column.
Checking for 1 instead of 0.
✗ Incorrect
We check if any element in the first row or first column is zero to mark flags.