Sliding Window Maximum
Sliding Window Maximum: Given an integer array nums and an integer k, a window of exactly k consecutive elements moves from left to right by one position at…
Given an integer array `nums` and an integer `k`, a window of exactly `k` consecutive elements moves from left to right by one position at a time. Return the maximum value in every window, in window order.
- `1 <= nums.length <= 10^5` - `-10^4 <= nums[i] <= 10^4` - `1 <= k <= nums.length` - The interactive visualizer accepts at most 12 values; longer valid inputs are execution-only.
Example 1: input nums = [1,3,-1,-3,5,3,6,7], k = 3; output [3,3,5,5,6,7]. Window by window: [1,3,-1] has maximum 3; [3,-1,-3] has maximum 3; [-1,-3,5] has maximum 5; [-3,5,3] has maximum 5; [5,3,6] has maximum 6; [3,6,7] has maximum 7. That gives [3,3,5,5,6,7].
Example 2: input nums = [1], k = 1; output [1].
Category: Sliding Window. Topic: sliding-window. Difficulty: Hard. Patterns: sliding-window, monotonic-stack.