Easy

Quiz

#219 Contains Duplicate II

APPROACH

Determine whether there exist two indices i and j in nums (with i != j) where the values are equal and the distance between indices is at most k.

Example 1:

Input: nums = [1,2,3,1], k = 3
Output: true

Example 2:

Input: nums = [1,0,1,1], k = 1
Output: true

Example 3:

Input: nums = [1,2,3,1,2,3], k = 2
Output: false
1 of 4
1:00

What is the optimal approach for this problem?