Challenge - 5 Problems
Matrix Zero Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Set Matrix Zeroes In Place after one zero found
What is the state of the matrix after running the Set Matrix Zeroes In Place algorithm on this input?
DSA Go
matrix := [][]int{ {1, 2, 3}, {4, 0, 6}, {7, 8, 9}, } // After calling setZeroes(matrix)
Attempts:
2 left
💡 Hint
Remember that all elements in the row and column of any zero element become zero.
✗ Incorrect
The zero at position (1,1) causes the entire row 1 and column 1 to be set to zero. So matrix[1][*] and matrix[*][1] become zero.
❓ Predict Output
intermediateOutput of Set Matrix Zeroes In Place with multiple zeros
What is the matrix after applying Set Matrix Zeroes In Place on this input?
DSA Go
matrix := [][]int{ {0, 2, 3}, {4, 5, 6}, {7, 8, 0}, } // After calling setZeroes(matrix)
Attempts:
2 left
💡 Hint
Zeros in first row and last column affect entire rows and columns.
✗ Incorrect
Zeros at (0,0) and (2,2) cause rows 0 and 2 and columns 0 and 2 to be zeroed. So matrix[0][*], matrix[2][*], matrix[*][0], matrix[*][2] become zero.
🔧 Debug
advancedIdentify the error in this Set Matrix Zeroes In Place implementation
What error will this Go code cause when run on a matrix with zeros?
DSA Go
func setZeroes(matrix [][]int) { rows := len(matrix) cols := len(matrix[0]) for i := 0; i < rows; i++ { for j := 0; j < cols; j++ { if matrix[i][j] == 0 { for k := 0; k < rows; k++ { matrix[k][j] = 0 } for l := 0; l < cols; l++ { matrix[i][l] = 0 } } } } }
Attempts:
2 left
💡 Hint
Modifying matrix elements while scanning causes repeated zeroing.
✗ Incorrect
Setting zeros immediately causes new zeros to appear during iteration, leading to repeated zeroing and incorrect results.
🧠 Conceptual
advancedSpace complexity of Set Matrix Zeroes In Place optimized approach
What is the space complexity of the optimal in-place Set Matrix Zeroes algorithm that uses the first row and column as markers?
Attempts:
2 left
💡 Hint
The algorithm uses matrix itself to store zero info.
✗ Incorrect
By using first row and column as markers, no extra arrays are needed, so space is constant.
🚀 Application
expertNumber of zeroed elements after Set Matrix Zeroes In Place
Given this matrix, how many elements will be zero after applying Set Matrix Zeroes In Place?
DSA Go
matrix := [][]int{ {1, 2, 3, 4}, {5, 0, 7, 8}, {9, 10, 11, 12}, {0, 14, 15, 16}, } // After calling setZeroes(matrix)
Attempts:
2 left
💡 Hint
Count all elements in rows and columns containing zeros, avoid double counting.
✗ Incorrect
Zeros at (1,1) and (3,0) cause rows 1 and 3 and columns 0 and 1 to be zeroed. Counting zeroed elements: row1(4), row3(4), col0(2 new), col1(2 new), total 12 unique zeroed elements.
