consider G as 1, B as 0
so actually its series of 1 and 0's

now consider any sequence GBGBBGGGBG will be represented as
1010011101

objective is to push all 1's at the right end.
all '10' pairs need to be swapped at the same time.
considering this take for ex 101
the number of swaps is equal to the number of zeroes b/w two consecutive 1's
if the number of zeroes turn out to be 0 that is we have series of 1's in
the sequence then the number of swaps is equal to length of the series of
1's -1 .
leading zeroes is nt a problem and hence can be left in calculation.
add all that is ur answer.

case 1:  11001
 will require 1(first two 1's are consecutive so 2 - 1 )+2(zeroes b/w two
consecutive 1's) = 3
         10101,01011,00111

case 2: 1001 only 2(two zeroes)
            0101,0011

case 3: 111011001
   will require 2(3 consecutive 1's)+1(single zero between 3rd and 4th
'1')+1(2 consecutive 1's)+2(two zeroes b/w last two 1's) = 6
110110101,101101011,011010111,010101111,001011111,000111111

it wrking f9 with this .
correct me if i am wrng.

On Mon, Jun 27, 2011 at 9:33 PM, harshit pahuja <hpahuja.mn...@gmail.com>wrote:

> hint is :  go for counting  ,not for shifting   o(n).  :P
>
>
> On Mon, Jun 27, 2011 at 9:29 PM, pacific :-) <pacific4...@gmail.com>wrote:
>
>> Can one of you provide some hints in solving this problem ?
>>
>>
>> On Sat, Jun 25, 2011 at 3:34 PM, kartik sachan 
>> <kartik.sac...@gmail.com>wrote:
>>
>>> @jitendra that's what i am asking for................what algo i should
>>> implement  to get process in 1 sec?
>>>
>>> --
>>> 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.
>>>
>>
>>
>> --
>> regards,
>> chinna.
>>
>>  --
>> 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.
>>
>
>
>
> --
> HARSHIT PAHUJA
> M.N.N.I.T.
> ALLAHABAD
>
>
>
>  --
> 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.

Reply via email to