@shreyas VA
  you are using O(n) extra space...

On Sat, Dec 4, 2010 at 8:46 PM, Shreyas VA <[email protected]> wrote:

> Given the size of the input array,
> construct array1 = {0, 1, 0, 1....} till n elements
>
> traverse through input array checking sum of 1's n 0's.
>
> at the end if both sums are equal return array1 else return input array.
>
> On Sat, Dec 4, 2010 at 12:06 AM, siva viknesh <[email protected]>wrote:
>
>>  Modified 2 color sort problem i.e. you are given an array of integers
>> containing only 0s and 1s.You have to place all the 0s in even
>> position and 1s in odd position. And if suppose, no. of 0s exceed no.
>> of 1s or vice versa then keep them untouched. Do that in ONE PASS and
>> without taking extra memory (modify the array in-place).
>>
>> For Example :
>>
>> Input Array: {0,1,1,0,1,0,1,0,1,1,1,0,0,1,0,1,1}
>> Output Array: {0,1,0,1,0,1,0,1,0,1,0,1,0,1,1
>> ,1,1}
>>
>> Write a solid secure code for it.
>>
>>
>> My solution:
>>
>>
>> .....i thought of a solution ..but it takes 2 passes !!
>>
>> in first pass count all no. of zeros nd ones
>>
>> and in 2nd pass check whether no. of zeros > no. of 1 s and vice
>> versa  and accordingly assign values to the same input array
>>
>> ....can anybody give the solution in single pass??
>>
>> ....
>>
>>
>>
>> --
>> Regards,
>> $iva
>>
>> --
>> 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]<algogeeks%[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]<algogeeks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
*Divesh*
(¨`·.·´¨) Always
  `·.¸(¨`·.·´¨ ) Keep
  (¨`·.·´¨)¸.·´Smiling!
   `·.¸.·´" Life can give u 100's of reason 2cry,but u can give life 1000's
of reasons 2Smile"

-- 
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.

Reply via email to