@rajnish: i think u missed the point , the matrix is binary.. so how will you store -1 in it.
@pacific: Will you solution work fine if 0 th row has all 1's and 0th column has atleast one zero.?? On Mon, Mar 7, 2011 at 1:09 AM, yogesh kumar <yoku2...@gmail.com> wrote: > @pacific: Good Algorithm > > // This is the preface solution of this problem [:)] > // Time complexity: O(n^2) > // Space complexity: O(1) > > public class BinaryMatrix > { > public static void main(String arg[]) > { > int[][] matrix = new int[][] > {{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}}; > int temp = 0; > temp = matrix[0][0]; > for(int i=1; i<matrix.length;i++) > { > matrix[0][0] &= matrix[0][i]; > temp &= matrix[i][0]; > } > for(int i=1;i<matrix.length;i++) > { > for(int j=1;j<matrix.length;j++) > { > matrix[0][i] &= matrix[j][i]; > matrix[i][0] &= matrix[i][j]; > } > } > for(int i=1;i<matrix.length;i++) > { > for(int j=1;j<matrix.length;j++) > { > matrix[i][j] = matrix[i][0] & matrix[0][j]; > } > } > for(int i=1; i<matrix.length;i++) > { > if(matrix[0][0] == 0) > { > matrix[0][i] = 0; > } > if(temp == 0) > { > matrix[i][0] = 0; > } > } > matrix[0][0] &= temp; > for(int i=0;i<matrix.length;i++) > { > for(int j=0;j<matrix.length;j++) > { > System.out.print(matrix[i][j] + " "); > } > System.out.print("\n"); > } > } > } > > -- > 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. > > -- 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.