Back to exercises

Sliding Window Maximum

Store indices in a deque so values stay in decreasing order. Remove indices that fall out of the window and pop smaller trailing values before appending the current index.

Coding Exercises Hard O(n)

Sliding Window Maximum

Store indices in a deque so values stay in decreasing order. Remove indices that fall out of the window and pop smaller trailing values before appending the current index.

Return the maximum value in each sliding window of size k.