dsa · easy

Contains Duplicate II

Return whether nums contains two equal values whose indices differ by at most k.

Arguments

Example

nums = [1,2,3,1], k = 3true (the two 1s are 3 apart).

nums = [1,2,3,1,2,3], k = 2false.

Constraints

1 <= nums.length <= 10^5 0 <= k <= 10^5 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

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

Expected:
true

Example 2

Input:
[1,0,1,1]
1

Expected:
true

Example 3

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

Expected:
false

Open in the Dojo editor