Dave has a nice idea but I cant get it to work =/ [[1, 0, 0, 1], [0, 0, 1, 0], [0, 0, 0, 0]] original matrix
[[1, 0, 1, 1], [1, 1, 1, 1], [0, 0, 1, 1]] dave's [[1, 1, 1, 1], [1, 1, 1, 1], [1, 0, 1, 1]] expected Maybe I converted it wrong. My method was basically the same as Anup's -- 1st pass fill rows and convert 1's to 2's. 2nd pass check for 2's and fill those columns. But complexity seems to be n*m*m + n*m*n = nm^2 + mn^2 which is about O(n^2 m^2) ? =/ I would like to get Dave's to work =P On Aug 31, 1:47 pm, siva viknesh <sivavikne...@gmail.com> wrote: > @dave...additionally u ve to do this...checking the 1st row nd 1st > column... > > if(a[0][0]) > set both first row and first column; > else > for(i=1;i<n;i++) > if(a[0][i]) > set first row; > else > set first column; > > On Aug 31, 10:34 pm, siva viknesh <sivavikne...@gmail.com> wrote: > > > > > > > > > dave s algo is nice :) > > > On Aug 31, 10:09 pm, Dave <dave_and_da...@juno.com> wrote: > > > > @Ashima: Scan all but the first row and the first column. If there is > > > a 1 in a row, set the first element of that row to 1. If there is a 1 > > > in a column, set the first element of that column to zero. Now, set > > > any element in all but the first row and the first column of the > > > matrix that has a 1 it the first element of its row or a 1 in its > > > first element of its colunn to 1. > > > > Dave > > > > On Aug 31, 12:02 pm, "Ashima ." <ashima.b...@gmail.com> wrote: > > > > > @dave wats d logic behind ur code > > > > > Ashima > > > > M.Sc.(Tech)Information Systems > > > > 4th year > > > > BITS Pilani > > > > Rajasthan > > > > > On Wed, Aug 31, 2011 at 9:05 AM, Dave <dave_and_da...@juno.com> wrote: > > > > > @Manish: > > > > > > for( i = 1 ; i < n ; ++i ) > > > > > for( j = 1 ; j < m ; ++j ) > > > > > if( a[i][j] != 0 ) > > > > > a[i][0] = a[0][j] = 1; > > > > > for( i = 1 ; i < n ; ++i ) > > > > > for( j = 1 ; j < m ; ++j ) > > > > > if( a[i][0] + a[0][j] != 0 ) > > > > > a[i][j] = 1; > > > > > > Dave > > > > > > On Aug 31, 8:40 am, manish kapur <manishkapur.n...@gmail.com> wrote: > > > > > > Input is a matrix of size n x m of 0s and 1s. > > > > > > > eg: > > > > > > 1 0 0 1 > > > > > > 0 0 1 0 > > > > > > 0 0 0 0 > > > > > > > If a location has 1; make all the elements of that row and column = > > > > > > 1. eg > > > > > > > 1 1 1 1 > > > > > > 1 1 1 1 > > > > > > 1 0 1 1 > > > > > > > Solution should be with Time complexity = O(n*m) and O(1) extra > > > > > > space > > > > > > -- > > > > > 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.-Hidequotedtext - > > > > > - Show quoted text - -- 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.