public boolean duplicate(int arr[],int k){
        Set<Integer> visited = new HashSet<Integer>();
        for(int i=0; i < arr.length; i++){
            if(visited.contains(arr[i])){
                return true;
            }
            if(i >= k){
                visited.remove(arr[i-k]);
            }
            visited.add(arr[i]);
        }
        return false;
    }
Write a function that determines whether a array contains duplicate 
characters within k indices of each other
src/com/interview/array/DuplicateWithinkIndices.java