[code]class Solution {public boolean containsNearbyDuplicate(int[] nums, int k) {// Corner Caseif(nums == null || nums.length == 0){return false;}Map<Integer, Integer> seen = new HashMap<>();for(int i = 0; i < nums.length; i++){if(seen.containsKey(nums[i])){if(i - seen.get(nums[i]) <= k){return true;}}// Add or update the valueseen.put(nums[i], i);}return false;}}