class Solution {
public boolean containsNearbyDuplicate(int[] nums, int k) {
HashSet<Integer>obj=new HashSet<>();
for(int i=0;i<nums.length;i++)
{
if(obj.contains(nums[i]))
{
return true;
}
else
{
obj.add(nums[i]);
if(obj.size()>k)
{
obj.remove(nums[i-k]);
}
}
}
return false;
}
}