```
class Solution {
```

public:

bool containsNearbyDuplicate(vector<int>& nums, int k)

{

int i,j;

vector<int> v;

vector<int> t;

for(i=0;i<nums.size();i++)

{

if(v[nums[i]]==1)

{

if(i-t[nums[i]]<=k)

return 1;

else

continue;

}

else

{

v[nums[i]]=1;

t[nums[i]]=i;

}

}

return 0;

}

};