everyday. It will always be useful to read content from other writers and practice a little something from their web sites. ]]>

One way around this is to keep a second matrix which flags the 0 locations We would then do a second pass through the matrix to set the zeros This would take O(MN) space

class Matrix

def initialize(input)

@input = input

@zeros = []

end

def solve

@input.each_with_index do |row, i|

row.each_with_index do |element, j|

@zeros << [i,j] if element == 0

end

end

@zeros.each do |x,y|

set_h_zero(x)

set_v_zero(y)

end

@input

end

private

def set_h_zero(row)

@input[row].map!{0}

end

def set_v_zero(col)

@input.size.times do |r|

@input[r][col] = 0

end

end

end