Reported July 2026
Amazonsliding window

Sliding Window Maximum

Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Amazon OA. Under 2s to a working solution.
Founder's read

Strip away the window talk and this Amazon problem, reported in July 2026, is a question about which old values still matter. Every window needs its max, and brute force rechecks k elements each time. The real answer is a monotonic deque that throws away anything that can never win again. If your OA invite lands in the next day or two, this is the shape to recognize. And if your mind goes blank mid-assessment, StealthCoder runs invisibly on screen and hands you the solution as a safety net.

The problem

Given an integer array nums and a window size k, return the maximum value in every contiguous window of length k, from left to right.

Function
maxSlidingWindow(nums: int[], k: int) → int[]

Examples
Example 1
nums = [1,3,-1,-3,5,3,6,7]
k = 3
return = [3,3,5,5,6,7]
Example 2
nums = [1]
k = 1
return = [1]

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: keep a deque of indices whose values are in decreasing order. For each new element, pop from the back while the back value is less than or equal to the new one, because those smaller values can never be a max once a bigger, newer one exists. Push the new index. Pop from the front if its index has slid out of the window, meaning index <= i - k. Once i >= k - 1, the front of the deque is your answer for that window. That's O(n) time, since each index enters and leaves once. The common pitfall is storing values instead of indices, which makes expiry impossible to check. Another is using a heap and ending up at O(n log k) with lazy deletion bugs. Watch the k = 1 case and the output length, which is n - k + 1. If you freeze on the deque logic during the live OA, StealthCoder is the hedge.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Sliding Window Maximum cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as sliding window maximum. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Amazon's OA.

Amazon reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Sliding Window Maximum FAQ

How hard is Sliding Window Maximum really?+

It's labeled hard, but the solution is short once you know the monotonic deque. The code is about ten lines. The difficulty is seeing that you can discard dominated elements. Brute force passes small cases, so you need the O(n) version to be safe on Amazon-sized inputs.

What's the trick to get O(n)?+

Use a deque of indices with decreasing values. Before pushing a new index, pop smaller values off the back. Before reading the max, pop the front if it's outside the window. The front is always the current window max. Each index is pushed and popped at most once.

Can I use a heap instead?+

Yes, a max-heap of (value, index) pairs works. Pop the top while its index is outside the window, then read the top. It runs in O(n log k) and is easier to get wrong. The deque is faster and cleaner, so lead with it unless you can't recall it.

Is this pattern still asked at Amazon?+

It was reported again in July 2026, so yes, treat it as live. Sliding window and monotonic deque variants keep showing up. Know this one cold, plus the neighbors like minimum in a window and next greater element.

How do I prepare in 48 hours?+

Write the deque solution from memory three times, then trace Example 1 by hand and watch the deque change. Test k = 1, k = n, duplicates, and all-negative arrays. Skip broad grinding. One pattern, done properly, beats ten half-learned ones.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Amazon.

OA at Amazon?
Invisible during screen share
Get it