educative.io

Educative

Why use heaps here?

Is there any benefits as to using heaps compared to just going through the array using the sliding window technique and add the result to a dynamic list?

1 Like

@Hansol_Hong, did you try it? What is its complexity? Is it better than the two heap approach?

I didn’t read the problem carefully and thought about finding an average instead of a median for some reason. Now I see I can’t use sliding window pattern alone when k > 2.

2 Likes

I had the same reaction as well. The regular sliding window pattern is faster, shorter and better.