Given an integer array nums and an integer k, return true if there are two distinct indices i and j in the array such that nums[i] == nums[j] and abs(i - j) &lt;= k.

&nbsp;
Example 1:

Input: nums = [1,2,3,1], k = 3
Output: true


Example 2:

Input: nums = [1,0,1,1], k = 1
Output: true


Example 3:

Input: nums = [1,2,3,1,2,3], k = 2
Output: false


&nbsp;
Constraints:


	1 &lt;= nums.length &lt;= 105
	-109 &lt;= nums[i] &lt;= 109
	0 &lt;= k &lt;= 105


class Solution:
    def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool:
        seen = {}
        for i, n in enumerate(nums):
            if n in seen and i - seen[n] <= k:
                    return True
            seen[n] = i
        return False
class Solution {
    public boolean containsNearbyDuplicate(int[] nums, int k) {
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (map.containsKey(nums[i]) && (Math.abs(map.get(nums[i]) - i) <= k) ) {
                return true;
            }
            map.put(nums[i], i);
        }
        return false;
    }
}
class Solution {
public:
    bool containsNearbyDuplicate(vector<int>& nums, int k) {
        unordered_map<int,int> m;
        for(int i=0;i<nums.size();i++){
            if(m.count(nums[i]) && i-m[nums[i]]<=k) return true;
            m[nums[i]]=i;
        }
        return false;
    }   
};
/**
 * @param {number[]} nums
 * @param {number} k
 * @return {boolean}
 */
var containsNearbyDuplicate = function(nums, k) {
    const duplicateCheck = {};
    let isValid = false;
    for(var indexI=0; indexI<nums.length;indexI++){
         if(duplicateCheck[nums[indexI]] > -1) {
            if(Math.abs(duplicateCheck[nums[indexI]] - indexI) <= k) {
              isValid = true;
              break;
            }

        }
        duplicateCheck[nums[indexI]] = indexI;
    }
    return isValid;
};
Contains Duplicate II