You receive an integer array nums together with integers indexDiff and valueDiff.
Determine whether there are two positions (i, j) for which all of the following hold:
i and j are different indices,abs(i - j) ≤ indexDiff,abs(nums[i] - nums[j]) ≤ valueDiffReturn true when at least one such pair is present; otherwise, return false.
Example 1:
Input: nums = [4,7,4], indexDiff = 2, valueDiff = 0
Output: true
Explanation:
Take (i, j) = (0, 2). The indices differ, since ; their distance is within the limit because ; and their values meet the bound because .
nums = [4,7, 4] indexDiff = 2 valueDiff = 0
true
Input: nums = [4, 7, 4] with indexDiff = 2 and valueDiff = 0.
Example 2:
Input: nums = [2,8,14,2,8,14], indexDiff = 2, valueDiff = 4
Output: false
Explanation:
No pair of distinct indices meets both the index-distance requirement and the value-difference requirement, so the result is false.
2 ≤ nums.length ≤ 10^5-10^9 ≤ nums[i] ≤ 10^91 ≤ indexDiff ≤ nums.length0 ≤ valueDiff ≤ 10^9nums = [4,7, 4] indexDiff = 2 valueDiff = 0
true
Input: nums = [4, 7, 4] with indexDiff = 2 and valueDiff = 0.