Contains Duplicate III
You are given an integer array nums and two integers indexDiff and valueDiff.
Find a pair of indices (i, j) such that:
i != jabs(i - j) <= indexDiffabs(nums[i] - nums[j]) <= valueDiff
Return true if such a pair exists, or false otherwise.
Example 1
Input
nums = [1,2,3,1], indexDiff = 3, valueDiff = 0Output
trueWe can choose
(i, j) = (0, 3) because the indices are different, abs(0 - 3) <= 3, and abs(1 - 1) <= 0.Example 2
Input
nums = [1,5,9,1,5,9], indexDiff = 2, valueDiff = 3Output
falseAfter trying all possible pairs
(i, j), none satisfies all three conditions.Constraints
- 2 <= nums.length <= 10^5
- -10^9 <= nums[i] <= 10^9
- 1 <= indexDiff <= nums.length
- 0 <= valueDiff <= 10^9