# Leetcode 220 - Contain duplicates III

Note:

• We can maintain a sliding window with size k.
• How do we put elements like [0, 1, 2, 3], t = 3 into the same bucket?
• Using x / t doesn’t work when  t == -1. Let’s use floor(x / t + 1) (In other languages other than JS, need to dicuss based on x is positive or not because in JS floor(-1.5) == -2).
• Use map.set(bucketIndex, nums[i]) to store elements.
• Always make sure there are only k buckets.
• When i >= k, we need to delete the bucket that nums[i - k] belongs to. Otherwise, in i + 1, there will be one extra bucket.

Question:

Given an integer array nums and two integers k and t, return true if there are two distinct indices i and j in the array such that abs(nums[i] - nums[j]) <= t and abs(i - j) <= k.

Example:

Code: