9.Set Matrix Zeroes

Given an m x n matrix. If an element is 0, set its entire row and column to 0. Do it in-place.

Input: matrix = [[1,1,1],[1,0,1],[1,1,1]]
Output: [[1,0,1],[0,0,0],[1,0,1]]

Solution I: (Using extra space)

Time Complexity: O(m * n), Space Complexity: O(m) , O(n)

Last updated

Was this helpful?