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

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

Example 1:
Input: {"nums":[1,2,3,1],"k":3}
Output: true
Input
arr ={"nums":[1,2,3,1],"k":3}

Check if duplicates exist within distance k=3

Window Size (k)

3

Array (sliding window of size k)
1
0
2
1
3
2
1
3
Seen Map (value → last index)

Empty

Current
In Window
Duplicate Found
Variables
No variables to display
DepthFunction Call
Stack empty
0/8