Contains Duplicate III
Examples
Example 1:
Input: nums = [1,2,3,1], indexDiff = 3, valueDiff = 0
Output: true
Explanation:
Example 2:
Input: nums = [1,5,9,1,5,9], indexDiff = 2, valueDiff = 3
Output: false
Explanation:
Example 1:
Input: nums = [1,2,3,1], indexDiff = 3, valueDiff = 0
Output: true
Explanation:
Example 2:
Input: nums = [1,5,9,1,5,9], indexDiff = 2, valueDiff = 3
Output: false
Explanation:
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, andreturn true if such pair exists or false otherwise.
We can choose (i, j) = (0, 3). We satisfy the three conditions: i ≠ j → 0 ≠ 3. abs(i - j) ≤ indexDiff → abs(0 - 3) ≤ 3. abs(nums[i] - nums[j]) ≤ valueDiff → abs(1 - 1) ≤ 0.
After trying all the possible pairs (i, j), we cannot satisfy the three conditions, so we return false.
2 ≤ nums.length ≤ 10^5-10^9 ≤ nums[i] ≤ 10^91 ≤ indexDiff ≤ nums.length0 ≤ valueDiff ≤ 10^9