@Minotauraus: ur approach is flawed!
the BEST solution would be to use a maxheap as navin said! :)
On Sep 21, 1:55 pm, Naveen Agrawal wrote:
> @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
@Minotauraus
Your algo is wrong
Consider this case:
12 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 numb
You are correct ...It depends on the max element's index...
--
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+unsu
1)Sort the first 10 elements (first window)
2)initialise i=1,l=j=10
3)last element is the maximum(l=10) printf(a[l])
4)i=i+1,j=j+1 if(a[j]>a[l])
then printf(a[j])
l=j
5)else printf(a[l])
6)if(i==l)
repeat from step 1
for worst case it needs 10 sorts
Correct if i am wrong
--
You recei
@Minotauraus, if we consider your scenario,
10 12 14 9 23 2 4 6 9 19 22 10 6 12 10
for 1st window max=23
second window max=23(23>22)
third windw max=23(23>10)
fourth window max=23(23>6)
fifth window max=23(23>12)
sixth window max =22(calculate the maximum in the window).
repeat again
So the numbe
You don't need any data structure.
Since the window moves by one element each, you can simply count 10
such moves and compare each new element with currMax.
If it's greater, overwrite currMax. After 10 moves you have your max
for that 10 element window, rinse and repeat.
On Sep 17, 1:31 am, Navin