You are given an integer array `nums` and two integers `indexDiff` and `valueDiff`. Find a pair of indices `(i, j)` such that: - `i != j`, - `abs(i - j) <= indexDiff`, - `abs(nums[i] - nums[j]) <= valueDiff`. Return `true` if such pair exists or `false` otherwise.
Example 1
Input: nums = [1,2,3,1], indexDiff = 3, valueDiff = 0
Output: true
Explanation: Indices 0 and 3 both hold 1. Their index gap is 3 ≤ indexDiff = 3 and their value gap is 0 ≤ valueDiff = 0.
Example 2
Input: nums = [1,5,9,1,5,9], indexDiff = 2, valueDiff = 3
Output: false
Explanation: Equal values sit 3 indices apart, which is more than indexDiff = 2. Nearby indices hold values that differ by 4 (1 vs 5, 5 vs 9) or 8 (9 vs 1), all more than valueDiff = 3. So no pair works.
Example 3
Input: nums = [1,2,3,1], indexDiff = 2, valueDiff = 1
Output: true
Explanation: Indices 0 and 1 hold 1 and 2. Their index gap is 1 ≤ 2 and their value gap is 1 ≤ 1, so a valid pair exists.
Drop each number into a bucket of width valueDiff+1. Two numbers in the SAME bucket automatically differ by at most valueDiff. Two numbers in ADJACENT buckets might, so check those explicitly. Keep only the last indexDiff buckets alive (a sliding window) so index distance is bounded.
Run checks all cases above. Submit evaluates all test cases.