A weather station records hourly temperatures temps. For every window of k consecutive hours (from the first full window to the last), report the swing: the highest temperature in the window minus the lowest. Return the list of swings.
Examples
Input: temps = [4, 2, 12, 3, 8], k = 3
Output: [10, 10, 9]
Explanation: [4, 2, 12] -> 12 - 2, [2, 12, 3] -> 12 - 2, [12, 3, 8] -> 12 - 3.
Input: temps = [5, -1, 7], k = 1
Output: [0, 0, 0]
Constraints
1 <= k <= len(temps) <= 10**5,-10**4 <= temps[i] <= 10**4.- Target complexity: O(n) time; re-scanning each window costs O(n * k).
Goals
- Maintain the window maximum with a decreasing deque of indices
- Maintain the window minimum with a second, increasing deque
- Evict indices that have left the window in O(1)