# 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).

- Using
- 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.

- When

`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:`

1 | Input: nums = [1,2,3,1], k = 3, t = 0 |

`Code:`

1 | /** |