You get an array of integers nums and two limits, indexDiff and valueDiff.
Look for two different positions i and j that satisfy both rules:
- They are close in position:
abs(i - j) <= indexDiff.
- Their values are close:
abs(nums[i] - nums[j]) <= valueDiff.
Return true if such a pair exists. Otherwise return false.
Examples
Example 1:
Input: nums = [1,9,3,7], indexDiff = 2, valueDiff = 2
Output: true
Explanation: Positions 0 and 2 hold 1 and 3. They are 2 apart in position and 2 apart in value.
Example 2:
Input: nums = [1,9,3,7], indexDiff = 1, valueDiff = 2
Output: false
Explanation: Neighbours differ by 8, 6 and 4 in value, which is always more than 2.
Example 3:
Input: nums = [8,8], indexDiff = 1, valueDiff = 0
Output: true
Explanation: Two equal numbers next to each other.