@atul.. First of all 6 is not in the heap but its index '0' is..
I think before also u had raised this question of heap stability and i did explain with an example in one of my previous posts that it won't affect the checks... I m repeating the same explanation here with the reason why it won't affect... Say, for the given sequence where u think it will cause a problem.... Now lets say that u are inside the while loop and the current top is '0' i.e. value A[0] = 6, Now, if currentstrt index is >0 say for ex- '4', then acc. to the following check the value A[0] = 6, won't be considered for currentStr and will be removed from the heap...After the removal the process of finding the next max/min will repeat inside the while loop: if (Top(MaxH) < currStartInd) '0' < '4' , hence remove and continue to loop.. Remove(MaxH); I have mentioned in one of my previous posts that the above check guarantees the heap stability... ------------------------------------------------------------- Please look for the post which starts with the below text , to refer to the code: /** @topcoder.. Below i have added a semi pseudocode for better understanding.. Let me know if u want further explanation.. **/ Also, please to the post which starts with the below text, where i have clarified ur doubts: /** @atul.. There are no stability or access issues with the code.. Below i have given explanation for ur concerns... */ ------------------------------------------------------------ If u find an example where the explanation fails, let me know... --------------------------------------------------------- On Jan 5, 12:44 am, gaurav bansal <gbgaur...@gmail.com> wrote: > @all > sorry for my prev post. > > On Jan 5, 12:42 am, gaurav bansal <gbgaur...@gmail.com> wrote: > > > > > > > > > your algo wont work for a[]={8,11,2} with k=7. > > acc to u,ans should be 3,but it is 2. > > you are not considering the diff between max and min value -- 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.