title: In a matrix put 0 in the row and column of a cell which contains 0 without using extra space
body: <p>Given a matrix, if a cell contains 0, then we have make entire row and column corresponding to the cell as 0. For example, if</p>
  
  <pre><code>      1 2 3
  M  =  0 4 5
        4 2 0
  </code></pre>
  
  <p>then the output should be </p>
  
  <pre><code>      0 2 0
        0 0 0
        0 0 0
  </code></pre>
  
  <p>The method I thought is as follows</p>
  
  <ol>
  <li>Make auxiliary arrays <code>row[]</code> and <code>col[]</code>. If a cell(i,j) contains 0 then, mark <code>row[i]</code> and <code>col[j]</code> as 0.(Initially <code>row[]</code> and <code>col[]</code> contains all 1s).</li>
  <li>Again traverse the whole matrix, if for cell(i,j), either of <code>row[i]</code> or <code>col[j]</code> is 0, then put cell(i,j) as 0.</li>
  </ol>
  
  <p>This takes O(m*n) time and O(m+n) space.</p>
  
  <p>How to optimize it further specially in terms of space.Any suggestions for improving time complexity are also welcomed.</p>