```
class Solution:
# @param {integer[]} nums
# @param {integer} k
# @return {boolean}
def containsNearbyDuplicate(self, nums, k):
d=dict()
if(len(nums)<=1 or k==0):
return False
for r in range(0,len(nums)):
d[str(r)]=nums[r]
dd=sorted(d.items(),key=lambda d:int(d[1]))
a=[]
b=[]
for k,v in dd:
a.append(int(k))
b.append(int(v))
for i in range(len(nums)-1):
if(b[i]==b[i+1]):
if (abs(a[i]-a[i+1])<=int(k)):
return True
return False
```