How about we go column-wise first. Search for a '1' in each row, if found, make it a '2' and all the elements below that, in that column '1'
1 0 0 1 2 0 0 2 0 0 1 0 > 1 0 2 1 0 0 0 0 1 0 1 1 Now search for a '2' in each row and if it is present make each element in that row except for that 2 a '1' 1 0 0 1 2 1 1 2 0 0 1 0 > 1 1 2 1 0 0 0 0 1 0 1 1 Now convert all 2's to '1's This solution needs verification on the complexity part. -- 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.