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 <tech.login....@gmail.com> 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 algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > 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 algoge...@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.