Sliding Window Maximum
You are given an integer array arr and a window size k. A window of length k slides from the very left to the very right of the array, moving one position at a time. For each position of the window, you must report the maximum element visible inside it.
The output is an array of length n - k + 1 where the element at index i is max(arr[i], arr[i+1], ..., arr[i+k-1]).
Examples
Input: [1,2,3]
Output: []
Input: [1,2,3]
Output: []
Hints
When the window slides, only one element enters and one leaves. Can you avoid re-scanning the whole window each time?
If a smaller element appears to the left of a larger one inside the window, can it ever become the maximum once the larger one arrives?
Expired elements (outside the current window) must be discarded. How can you tell when an element is no longer in scope?
Sliding Window Maximum
You are given an integer array `arr` and a window size `k`. A window of length `k` slides from the very left to the very right of the array, moving one position at a time. For each position of the window, you must report the maximum element visible inside it.