FreeCareerPath
Build the PrimitiveHard

Sliding Window Maximum

Write `max_sliding_window(nums, k)` returning the maximum of every contiguous window of width `k`, left to right. max_sliding_window([1,3,-1,-3,5,3,6,7], 3) -> [3, 3, 5, 5, 6, 7] A heap gives O(n log k). O(n) needs a deque holding *indices* whose values decrease from front to back: before pushing, pop every smaller value off the back (they can never be the maximum again while the new one is in the window), and drop the front once it falls outside. Store indices, not values, or you cannot tell when the front expires.

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "Sliding Window Maximum" are saved to your account — logging in takes a few seconds.