← 返回 uber 的题目列表Sliding Window Maximum
类型:qbank
Onsite coding prompt equivalent to Sliding Window Maximum. Given `nums` and window size `k`, return the maximum value in every contiguous window of length `k`.
Requirements
Input: integer array nums and integer window size k.
For every contiguous subarray of length k, output the maximum element in that window.
Preserve the original left-to-right window order in the output.
Expected performance is better than scanning each window independently.
Notes
The prompt appeared in a problem-solving round paired with another hard array prompt, so time management matters.
Clarify edge cases: k == 1, k == len(nums), duplicate maxima, and negative values.
Preparation
Drill the monotonic queue implementation until enqueue/dequeue expiry logic is automatic.
Practice explaining why stale indices must be removed before reading the front of the deque.