```
public boolean containsNearbyDuplicate(int[] nums, int k) {
int[][] table = new int[3][nums.length];
for(int i = 0; i < nums.length; i++)
{
int num = nums[i];
int place = num % nums.length;
if (place < 0) place += nums.length;
while (table[0][place] != 0)
{
if (table[1][place] == num && table[2][place] + k >= i)
return true;
else if (table[1][place] == num)
break;
else
place = (place + 1) % nums.length;
}
table[0][place] = 1;
table[1][place] = num;
table[2][place] = i;
}
return false;
}
```