Algorithm · Uber · Medium
Requirements Given an integer array nums and an integer limit. Return the size of the longest non-empty consecutive segment whose elements differ by at most limit from one another. Put another way, a segment qualifies if max(segment) - min(segment) ≤ limit; checking its smallest and largest values is sufficient to cover every pair. Constraints: 1 ≤ nums.length ≤ 10^5, 1 ≤ nums[i] ≤ 10^9, 0 ≤ limit ≤ 10^9. Since the numbers may span a very large range, counting or…
Checking your access…