"Title description"
Given an array of n integers with duplicate number, and a moving window (size k), move the window at each iteration from the Start of the array, find the maximum number inside the window at each moving.
Give an array of integers that may contain duplicates, and a sliding window of size k , sliding the window from left to right in the array to find the maximum value within each window in the array.
"Topic link"
www.lintcode.com/en/problem/sliding-window-maximum/
"Problem Analysis"
Iterates over the array nums, using a double-ended queue deque to maintain an array subscript within the sliding window that is likely to be the largest element. Because each element in the array will only be enqueued and out of the queue at most, the averaging time complexity is O (n). The current subscript is I, then the active subscript range for the sliding window is [i-(k-1), I]. If the element in the deque is labeled I-(k-1), it pops from the team head, and the elements in the deque are queued in ascending order from the end of the queue. This ensures that the array subscript range in the deque is [i-(k-1), I], which satisfies the sliding window requirements.
When I queue up from the end of the team, the index of the array with the tail of the popup line is not more than nums[i] (these ejected elements become meaningless due to the addition of new elements). Deque's team head element is the maximum value of the current sliding window
"Reference Answer"
www.jiuzhang.com/solutions/sliding-window-maximum/
Lintcode362 Sliding Window Maximum Solution