@Minotauraus

Your algo is wrong
Consider this case:
1    2  3   4   5   6  7   8   9  10 11 12 13  14 15 16  17 18 19 20
99 98 97 96 95 94 93 92 91 90 89 88  87  86 85 84 83 82 81 80

According to your algo
1)Max for first window =99,i.e,curr max=99
2)Compare with new element,i.e wlth element number (11) = 89,as it is small
than curr max ,curr max=99 which is wrong as the correct answer is 98.

Improvisation of your algo but complexity of O(n2)

if curr max<new elment ,
then curr max = new elemnt
else
*again calculate max of the whole window*


So it will be better to use heap as suggested by Navin Naidu.....,which
reduces the complexity..

-- 
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.

Reply via email to