Take an array of size of the length of the string. fill the array positions with one where string contains 1, and -1 where it is 0
Now for each i (1,n-1) perform the following operation a[i] = a[i-1] + a[i] now a[i] will contains sum of values from a[0] to a[i] in original array. Now only thing remains to find is two indexes in this array such that a[i] = a[j] where ever this condition is met ( i,j ] is a solution or if for some i a[i] = 0 in this case [0,i] will be a solution this can be done using hashing hash the values in the array of size 2*n+1. as range of values is -n to n and keep track of max interval. On Fri, Jul 1, 2011 at 3:22 PM, Anantha Krishnan < [email protected]> wrote: > Given a string containing 0's and 1's. One would need to find the longest > sub-string such that the count of 0's is equal to the count of 1's in the > largest sub string. > > Regards > Anantha Krishnan > > -- > 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. > -- Sunny Aggrawal B-Tech IV year,CSI Indian Institute Of Technology,Roorkee -- 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.
