Longest subarray with absolute difference within a limit

0
Remix

Given an integer array and a limit, return the length of the longest contiguous subarray in which any two elements differ by at most limit.

The expected answer is O(n): a sliding window that keeps the window's minimum and maximum in two monotonic deques.

UberCodingLast asked May 2026
No answer yet. Write the first one; the best answer gets endorsed.