public boolean rearrangeExactKDistanceAway(char input[],int d){
        PriorityQueue<CharCount> heap = new PriorityQueue<CharCount>();
        Map<Character,Integer> map = new HashMap<Character,Integer>();
        for(int i=0; i < input.length; i++){
            int count = 1;
            if(map.containsKey(input[i])){
                count = map.get(input[i]);
                count++;
            }
            map.put(input[i], count);
            input[i] = 0;
        }
        for(Character ch : map.keySet()){
            CharCount cc = new CharCount();
            cc.ch = ch;
            cc.count = map.get(ch);
            heap.add(cc);
        }
        
        while(heap.size() > 0){
            CharCount cc = heap.poll();
            int i;
            for(i=0; i < input.length && input[i] != 0; i++);
            if(i == input.length){
                return false;
            }
            while(cc.count > 0 && i < input.length){
                input[i] = cc.ch;
                i = i + d;
                cc.count--;
            }
            if(cc.count > 0){
                return false;
            }
        }
        return true;
    }
http://www.geeksforgeeks.org/rearrange-a-string-so-that-all-same-characters-become-at-least-d-distance-away/
src/com/interview/string/RearrangeDuplicateCharsdDistanceAway.java