Use Max-Heap, add first ten elements, the root element will be max, Next Iteration, remove a[0] and add a[10], max-heapify.
On Fri, Sep 17, 2010 at 1:48 PM, Tech Id <[email protected]> wrote: > You have an array of 100 integers. > There is a window of 10 elements which starts from 0th element and > moves by 1 element till the 90th element. > We need to print the maximum element for all the positions of the > window. > > Hint: > For the first position of the window, you have to find the maximum as > done normally for any array. > After that, when the window moves by 1 element, you just have to > consider one more element and forget the very first element to find > the new maximum. Thus, after the first max, it should take much less > time to find the max for all the other window positions. > > -- > 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. > > -- Thanks & Regards, - NMN -- 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.
