[algogeeks] Re: longest interval

2010-11-03 Thread Gaurav Singh
@sumat In the example given by you. the longest interval is [0...7] and not [3...8]. Something wrong with your algo. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscri

Re: [algogeeks] Re: longest interval

2010-11-03 Thread sumant hegde
Agree, the true answer is [0,7]. My previous post happened to be incorrect illustration of a correct program, as the attached code returns 0,7 only. The code (correctly) assumes a hidden 0 at *diff [-1]* always, so the longest interval that can be retained is (0,7) in this case. On Wed, Nov 3, 201

[algogeeks] Re: longest interval

2010-11-03 Thread Soumya Prasad Ukil
why not the answer (0,7)? On Nov 1, 4:02 pm, sumant hegde wrote: > Say diff [i] = (no. of 1s in B[ 0...i ]) - (no. of 1s in A[0...i]). In other > words the subarray B(0,i) contains diff(i) no. of more 1s than the subarray > A[0,i]. And  diff[i] < 0 indicates the excess of 1s in A's subarray. > Ex