1.) Traverse the whole matrix and replace each 0 value with -1.
2.) Traverse the matrix again,all the 1 values are replaced with 0 in
the row and column of the index where a -1 value is found.
3.) Set all -1 values to zero and we have the output array.
time complexity: O(n^2)
space complexity: O(1)


On Feb 27, 2:29 am, gaurav gupta <1989.gau...@googlemail.com> wrote:
> A NxN binary matrix is given. If a row contains a 0 all element in the
> row will be set to 0 and if a column contains a 0 all element of the
> column will be set to 0. You have to do it in O(1) space.
>
> example :
>
> input array :
>
> 1 0 1 1 0
> 0 1 1 1 0
> 1 1 1 1 1
> 1 0 1 1 1
> 1 1 1 1 1
>
> result array :
>
> 0 0 0 0 0
> 0 0 0 0 0
> 0 0 1 1 0
> 0 0 0 0 0
> 0 0 1 1 0
>
> Thanks & Regards,
> Gaurav Gupta

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to