219. Contains Duplicate II

Practice Contains Duplicate II for free on NudgeCode: Easy, Sliding Window pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

Return true if there are two different indices i and j with nums[i] == nums[j] and abs(i - j) <= k.

Example

nums = [1,2,3,1], k = 3        ->  true
nums = [1,2,3,1,2,3], k = 2    ->  false

Constraints