```
def containsNearbyDuplicate(self, nums, k):
h = set([])
j = -(k+1)
for i in xrange(len(nums)):
if j>=0:
h.discard(nums[j])
if nums[i] in h:
return True
h.add(nums[i])
j+=1
return False
```