← Questions

Longest subarray with absolute difference within a limit

0
UberCodingLast asked May 2026

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.

Write and test your solution herePython in your browser, the question's tests level by level, saved for you.Sign in to start coding