Longest Continuous Subarray with Absolute Difference at Most Limit

Given integer array nums and nonnegative limit, return the greatest length of a nonempty contiguous subarray for which every pair of values differs by at most…

Given integer array nums and nonnegative limit, return the greatest length of a nonempty contiguous subarray for which every pair of values differs by at most limit. Equivalently, maximum minus minimum must be at most limit. Return the length, not the window's values.

- 1 <= nums.length <= 100000. - -2147483648 <= nums[i] <= 2147483647; 0 <= limit <= 2147483647. - Inputs are strict integers; every singleton is valid. - Java/C++ must widen before subtracting extrema; the difference can reach 4294967295. - Teaching traces use at most 12 values and the ARRAY_TARGET integer range; coding retains all signed-int32 bounds.

Example 1: input nums = [8,2,4,7], limit = 4; output 2. The longest valid windows have length 2; [2,4] and [4,7] qualify.

Example 2: input nums = [1,1,1,2], limit = 0; output 3. The first three equal 1s have range zero; adding 2 requires repair.

Example 3: input nums = [1,5,9], limit = 4; output 2. Each adjacent pair has range 4 exactly; the length-3 window has range 8.

Category: Queues. Topic: queue. Difficulty: Medium. Patterns: linear-scan.