Set Matrix Zeroes
Reported by candidates from Tekion's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Tekion OA reported in July 2025 includes Set Matrix Zeroes, and the trap is a solution that looks right until a zero gets written too early. If you zero a row as you scan, you create fake zeroes and wipe the whole grid. The input also demands constant extra space, so a copy of the matrix is out. The real pattern is a matrix marker trick, not BFS, despite what the hint suggests. If you blank mid-assessment, StealthCoder runs invisibly on your desktop and gives you the in-place solution as a safety net.
The problem
Given an m x n integer matrix matrix, if an element is 0, set every element in its row and column to 0. Modify the matrix in place using constant extra space, then return the transformed matrix. Function setZeroes(matrix: int[][]) → int[][] Examples Example 1 matrix = [[1,1,1],[1,0,1],[1,1,1]] return = [[1,0,1],[0,0,0],[1,0,1]] The zero at row 1, column 1 makes the entire middle row and middle column zero. Example 2 matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]] return = [[0,0,0,0],[0,4,5,0],[0,3,1,0]] The zeroes in the first row make the first and fourth columns zero, and the first row is already required to become all zeroes. Constraints m == matrix.length. n == matrix[0].length. 1 <= m, n <= 200. -2^31 <= matrix[i][j] <= 2^31 - 1.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is to use the first row and first column of the matrix as your marker storage. Scan the grid, and when you hit a zero at (i, j), mark matrix[i][0] and matrix[0][j] as zero. Before that, record two booleans: does the first row originally contain a zero, and does the first column originally contain a zero. Then walk the inner cells from (1,1) and zero any cell whose row marker or column marker is zero. Finally, zero the first row and first column using those two booleans. The pitfall is skipping those booleans, because the markers overwrite real data and you can't tell which zeroes were original. Another mistake is zeroing during the first scan, which cascades. Time is O(m*n), space is O(1). If you freeze on the ordering of the final steps, StealthCoder is the hedge during the live OA, since it reads the problem and hands you the order.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Set Matrix Zeroes cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as set matrix zeroes. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Tekion's OA.
Tekion reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Set Matrix Zeroes FAQ
What's the trick in Set Matrix Zeroes?+
Store the markers inside the matrix itself. Use the first row and first column to flag which rows and columns need zeroing. That gives O(1) extra space. Track the first row and first column separately with two booleans, because they double as marker storage and would otherwise lose their original state.
Is this a BFS problem like the hint says?+
No. BFS doesn't fit here. It's a matrix problem with in-place marking. You scan once to record zero positions, then scan again to apply them. Trying a flood-fill approach will overcomplicate it and likely break the constant space requirement.
What edge case breaks the naive solution?+
Zeroing a row or column immediately while scanning. The new zeroes look original to later iterations, so you wipe far more than needed. The fix is to separate marking from applying, and to protect the first row and column with flags before using them as markers.
How hard is this really for the Tekion OA?+
It's a medium. The logic is short, but the ordering is easy to botch. Most failures come from the first row or first column handling. Write the two booleans first, mark, apply to the inner cells, then fix the borders last. Test with example 2, which has zeroes in the first row.
How do I prepare in 48 hours?+
Code this problem from scratch twice without looking. First with O(m+n) extra arrays for rows and columns, then upgrade to O(1) using the first row and column. Test on a 1x1 grid, a single row, a single column, and a grid where the top-left cell is zero.