Sponsored Reserved space — layout preview until AdSense is connected
hard +40 pts

Sliding window maximum

Deque for O(n) window max.

Implement `sliding_max(nums: list[int], k: int) -> list[int]`. Return the max of each sliding window of size k.

Constraints

1 ≤ k ≤ len(nums) ≤ 10^5

Example

>>> sliding_max([1,3,-1,-3,5,3,6,7], 3)
[3,3,5,5,6,7]
40 points ~35 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Maintain a deque of indices; keep only potentially useful (non-decreasing from back). Pop front if it's out of window.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.
Sponsored Reserved space — layout preview until AdSense is connected