Longest Stable Window — Solution & Editorial
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)
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)