Standard Bar Arrays · Medium O(m * n) · O(1)
A monitoring board stores sensor readings on a rectangular grid. A node reading exactly zero means the bus is faulty, and any row or column containing such a reading must be wiped to zeros to avoid propagating bad data. Perform the wipe in place with constant extra space, without cascading wipes caused by your own edits.
Input: An m x n matrix of integers.
Output: The same matrix with every element of any row or column that originally contained a zero set to 0.
1 <= m, n <= 200-2^31 <= matrix[i][j] <= 2^31 - 1The wipe must happen in place with constant extra spaceInput: {"matrix":[[1,1,1],[1,0,1],[1,1,1]]}
Output: [[1,0,1],[0,0,0],[1,0,1]]
The faulty node lies in the middle, so its entire row and column become zeros.
Input: {"matrix":[[0,1,2,0],[3,4,5,2],[1,3,1,5]]}
Output: [[0,0,0,0],[0,4,5,0],[0,3,1,0]]
Two faulty readings wipe rows 0 and the first and last columns, leaving only the interior cells intact.