1 1 0 1
0 1 1 1
1 1 1 1
1 1 1 0
row0 is true
col0 is true
for (int i=1; i<n;i++)
for (int j=1;j<m;j++)
if (a[i][j] == 0) {a[i][0]=0; a[0][j]=0;}
now after this
1 1 0 0
0 1 1 1
1 1 1 1
0 1 1 0
for (int i=1; i<n;i++)
if (a[i][0] ==0) for (int j=1; j<m;j++) a[i][j]=0;
for (int j=1; i<m;j++)
if (a[0][j] ==0) for (int i=1; i<n;i++) a[i][j]=0;
after this
1 1 0 0
0 0 0 0
1 1 0 0
0 0 0 0
because of row0 and col0 vars
final output is
0 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652
On Tue, Oct 4, 2011 at 7:49 AM, rahul sharma <[email protected]>wrote:
> @ashish can u give an xample.....plz...i have read a lot archives ...but
> cant find in 0(1) space....u using 2 var only...plz give xample...nended
> urgent.thnx
>
>
> On Tue, Oct 4, 2011 at 7:26 AM, Ashish Goel <[email protected]> wrote:
>
>> keep two var row0 and col0 for checking if there is any 0 in row0flag
>> /col0flag
>>
>> now walk over elements from 1,1 to n,m and set corresponding entry in 0th
>> row /column if you hit a zero.
>>
>> now walk over zeroth column and rwo and set the complete row/col if a 0 is
>> there in 0th row/col.
>>
>> after this based on row0flag/col0flag, set oth col/row values to 0.
>>
>> Best Regards
>> Ashish Goel
>> "Think positive and find fuel in failure"
>> +919985813081
>> +919966006652
>>
>>
>>
>> On Mon, Oct 3, 2011 at 12:08 PM, rahul sharma <[email protected]>wrote:
>>
>>> yeah it is wrong......i have a solution but uses 0(n+m) space.....i need
>>> it in 0(n*m) tymand o(1) space
>>>
>>>
>>> On Mon, Oct 3, 2011 at 11:55 AM, shady <[email protected]> wrote:
>>>
>>>> search archives :-/
>>>>
>>>>
>>>> On Mon, Oct 3, 2011 at 11:47 AM, pranav agrawal <
>>>> [email protected]> wrote:
>>>>
>>>>> @rahul sharma, i ran this code, it is producing wrong answer :|
>>>>>
>>>>> check it, http://codepad.org/THv1hJq1
>>>>>
>>>>> anyone with correct solution?
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Algorithm Geeks" group.
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msg/algogeeks/-/26XU3UBqZ6EJ.
>>>>>
>>>>> To post to this group, send email to [email protected].
>>>>> To unsubscribe from this group, send email to
>>>>> [email protected].
>>>>> 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 [email protected].
>>>> To unsubscribe from this group, send email to
>>>> [email protected].
>>>> 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 [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected].
>>> 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 [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> 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 [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> 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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.