Intuition
- Using a heap to maintain the index, remove and add the borders, and add the peek value to the final result.
solution
|
|
Follow Up
Solve in linear time.
solution
- Using deque to maintain the index of large numbers in descending.
- When the head is beyond the window range, delete it.
- When the incoming number is larger than the tail, then poll the tail, until the number is smaller than the tail or the deque is empty.
- The head is the largest number in the current window.
|
|