Problems > Longest Stable Window > Editorial

Longest Stable Window — Solution & Editorial

Back to the Problem

Sliding window maintaining a max-deque and a min-deque; while their difference exceeds K, advance the left edge (popping deque fronts that fall out).

Complexity: O(N)