← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
You are given an integer array nums and an integer limit. Return the length of the longest continuous subarray such that the absolute difference between the maximum and minimum element in the subarray is less than or equal to limit.
Example 1:
Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: The longest subarray is [2, 4, 7] with maximum absolute difference of 5 - 2 = 3.
Example 2:
Input: nums = [10,1,2,4,7,2], limit = 5 Output: 4 Explanation: The longest subarray is [2, 4, 7, 2] with maximum absolute difference of 7 - 2 = 5.
Example 3:
Input: nums = [7,3,6,2], limit = 2 Output: 2
1 <= nums.length <= 10^51 <= nums[i], limit <= 10^5