```
class Solution(object):
def containsNearbyDuplicate(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: bool
"""
if k>=len(nums):
return len(set(nums)) < len(nums)
i=0
while i+k < len(nums):
s = set(nums[i:i+k+1])
if len(s)<=k:
return True
break
i+=1
return False
```