Re: [algogeeks] Longest Bitstring with equal 0s and 1s

2010-08-01 Thread Anand
http://codepad.org/RrtoXLTX On Sun, Aug 1, 2010 at 5:09 AM, Nikhil Jindal wrote: > Here's a possible O(n) soln: > > for all i, I calculate a[i].diff as number of zeroes - number of ones ones > from a[0] to a[i]. > > I do this in O(n). > > Also, I make a list of all the indexes that have a differe

Re: [algogeeks] Longest Bitstring with equal 0s and 1s

2010-08-01 Thread Nikhil Jindal
Here's a possible O(n) soln: for all i, I calculate a[i].diff as number of zeroes - number of ones ones from a[0] to a[i]. I do this in O(n). Also, I make a list of all the indexes that have a difference d(for all possible d, which is n). Now, for it to be possible that the number of ones and n

[algogeeks] Longest Bitstring with equal 0s and 1s

2010-08-01 Thread Ram Kumar
Given an array of 0s and 1s in any order, find the longest sequence that has equal number of 0s and 1s. 0 0 0 0 1 1 1 1 0 0 //array 0 1 2 3 4 5 6 7 8 9 //index ans1 (0,7) ans2 (1,8) ans3 (2,9) all having 4 0's and 4 1's -- Regards, Ramkumar.G -- You received this message because