```
bool containsNearbyDuplicate(int* nums, int numsSize, int k) {
if(numsSize ==0) return false;
if(k>numsSize) k= k% numsSize;
int i, min= INT_MAX, max = INT_MIN;
for(i=0; i<numsSize; i++){
min = min< nums[i]? min: nums[i];
max = max> nums[i]? max: nums[i];
}
int *hash = malloc((max-min+1)* sizeof(int));
memset(hash, -1, (max-min+1)*sizeof(int));
for(i=0; i<numsSize; i++){
if(hash[nums[i]-min] == -1){
hash[nums[i]-min] = i;
}
else if((i-hash[nums[i]-min]) <= k){
return true;
}
else{
hash[nums[i]-min] = i;
}
}
return false;
}
```