I have to say the first_row, first_column solution in the discussions is the best idea in my opinion. However, here I present another O(1) space, assuming that -2147483647 is not an element in the matrix, so I can treat it as a placeholder.

The idea is we do rows and columns separately.

First, we do rows, if there are zeros in a row[i],

a) if matrix[i][j] = 0, we assign matrix[i][j] = placeholder (-2147483647)

b) if matrix[i][j] != 0, we assign matrix[i][j] = 0

Then, we do columns, in the matrix, if there is an element matrix[i][j] == placeholder, then I assign the whole column as 0s.

The extra space is O(1)

The time complexity is O(3mn + n)

```
def set_zeroes(matrix)
place_holder = -(1 << 32)
#fill rows
for i in 0...matrix.length
count = 0
matrix[i].each {|x| count += 1 if x === 0}
if count > 0
for j in 0...matrix[i].length
if matrix[i][j] === 0
matrix[i][j] = place_holder
else
matrix[i][j] = 0
end
end
end
end
#fill columns
for i in 0...matrix.length
for j in 0...matrix[i].length
if matrix[i][j] === place_holder
for k in 0...matrix.length
matrix[k][j] = 0
end
end
end
end
return nil
end
```