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 Go
for i := 0; i < len(matrix); i++ { for j := 0; j < len(matrix[0]); j++ { if matrix[i][j] == 0 { matrix[i][0] = [1] matrix[0][j] = 0 } } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 to mark the row or column.
Not marking the first row or column at all.
✗ Incorrect
We mark the first cell of the row and column as 0 to indicate that entire row and column should be zeroed later.
2fill in blank
mediumComplete the code to zero out the cells based on marks in the first row and column.
DSA Go
for i := 1; i < len(matrix); i++ { for j := 1; j < len(matrix[0]); j++ { if matrix[i][0] == [1] || matrix[0][j] == 0 { matrix[i][j] = 0 } } }
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 1 instead of 0 in the condition.
Not using logical OR to check both row and column markers.
✗ Incorrect
We check if the first cell of the row or column is zero to decide if the current cell should be zeroed.
3fill in blank
hardFix the error in the code that handles zeroing the first column if needed.
DSA Go
if firstColHasZero { for i := 0; i < len(matrix); i++ { matrix[i][[1]] = 0 } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 for the first column index.
Using negative or out-of-range indices.
✗ Incorrect
The first column index is 0, so we set matrix[i][0] to zero.
4fill in blank
hardFill both blanks to check if the first row has zero and mark it.
DSA Go
firstRowHasZero := false for j := 0; j < len(matrix[0]); j++ { if matrix[[1]][j] == 0 { firstRowHasZero = true break } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 or last index instead of 0 for the first row.
Checking columns instead of rows.
✗ Incorrect
The first row index is 0, so we check matrix[0][j] for zeros.
5fill in blank
hardFill all three blanks to zero the first row if needed and complete the function.
DSA Go
if firstRowHasZero { for j := 0; j < len(matrix[[1]]); j++ { matrix[[2]][j] = [3] } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong row index for the first row.
Setting cells to 1 or -1 instead of 0.
✗ Incorrect
We zero the first row (index 0) by setting matrix[0][j] = 0 for all columns.
