Assuming A[1......n]
i=1,j=n
calculate the initial sum and length of array
let it be s and l
now
if s > l/2 then {
.........if a[i]=1 then i++
.........elseif a[j]=1 then j++
.........else i++
}
if s < l/2 then {
.........if a[i]=0 then i++
.........elseif a[j]=0 then j++
.........else i++
}
if s=l/2 then it (i,j) is ur answeri dont know it works for sure or not but its an O(n) On Tue, Jan 4, 2011 at 2:08 PM, bittu <[email protected]> wrote: > You have a array of 0's and 1's. e.g. > 0001011101001010100101010101100111 > Find the maximum contiguous subsequence of the above sequence so the > number of 0's and 1's in that subsequence are equal > > > Regards > Shashank Mani > > -- > 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. > > -- Regards Aditya Kumar B-tech 3rd year Computer Science & Engg. MNNIT, Allahabad. -- 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.
