174. Contains Duplicate III

HardSliding Window

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.

Examples

Input: [1,2,3,1] 3 0

Output: true

Explanation: Indices 0 and 3 both hold 1: |0-3|=3 <= 3 and |1-1|=0 <= 0.

Constraints

  • 2 <= nums.length <= 10^5
  • -10^9 <= nums[i] <= 10^9
  • 1 <= indexDiff <= nums.length
  • 0 <= valueDiff <= 10^9
Loading...

Run checks all cases above. Submit evaluates all test cases.