Problem
You get an integer array nums and an integer k. A window of size k covers k consecutive items of nums.
The window starts at the left end of nums. At each step, the window moves one position to the right. It stops when it covers the last item.
Return an array with the largest value in the window at each position.
Example 1
- Input:
- nums = [4,2,12,3,8,1,7], k = 3
- Output:
- [12,12,12,8,8]
- Explanation:
- The first window is
[4, 2, 12], and its largest value is 12. The last window is[8, 1, 7], and its largest value is 8.
Example 2
- Input:
- nums = [5,-3,9], k = 1
- Output:
- [5,-3,9]
- Explanation:
- Each window holds one item, so the answer is a copy of
nums.
Example 3
- Input:
- nums = [-1,-5,-2,-8], k = 4
- Output:
- [-1]
Constraints
- 1 <= nums.length <= 10^5
- -10^4 <= nums[i] <= 10^4
- 1 <= k <= nums.length
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit
Coding · Array · Heap (Priority Queue) · Monotonic Queue
- Shortest Subarray with Sum at Least K
Coding · Array · Binary Search · Heap (Priority Queue)
- Count Subarrays With Fixed Bounds
Coding · Array · Monotonic Queue · Queue
- Maximum Coins From K Consecutive Bags
Coding · Array · Binary Search · Greedy
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 5 records
Amazon
Leetcode 239. Sliding Window Maximum
Reported Jan 16, 2025 · 1 source report
SENIOR
Source snapshot: Nov 12, 2026
View sourceMeta
Leetcode 239. Sliding Window Maximum
Reported May 4, 2025 · 3 source reports
MID_LEVEL
Source snapshot: Nov 12, 2026
View sourceMicrosoft
Leetcode 239. Sliding Window Maximum
Reported Feb 14, 2026 · 2 source reports
MID_LEVEL
Source snapshot: Nov 12, 2026
View sourceNetflix
Leetcode 239. Sliding Window Maximum
Reported Mar 20, 2026 · 1 source report
SENIOR
Source snapshot: Nov 12, 2026
View source