class UncommonLetterMap {

    public String getMinifiedWord(String word) {
        Queue<LetterFreqPair> mostInfreq = new LinkedList<LetterFreqPair>();
        PriorityQueue<LetterFreqPair> infreqHeap = new PriorityQueue<LetterFreqPair>();
        for (char letter : word.toCharArray()) {
            letter = this.sofitMap.containsKey(letter) ? this.sofitMap.get(letter) : letter;
            int ind = letter_freq_list.indexOf(letter);
            if (ind != -1) {
                if (infreqHeap.size() <= this.len_min_word || ind > infreqHeap.peek().freq) {
                    LetterFreqPair lfp = new LetterFreqPair(letter, ind);
                    mostInfreq.add(lfp);
                    infreqHeap.add(lfp);
                }
                if (mostInfreq.size() > this.len_min_word) {
                    mostInfreq.remove(infreqHeap.poll());
                }
            }
        }

        String out = "";
        for (LetterFreqPair lfp : mostInfreq) {
            out += lfp.getLetter();
        }

        return out;
    }

}

class UncommonLetterMapTest {

    @Test
    public void TestGetMinifiedWord() throws Exception {

        UncommonLetterMap ulm = new UncommonLetterMap(3);
        assertEquals("אבג",ulm.getMinifiedWord("אבג"));
        assertEquals("בגד",ulm.getMinifiedWord("אבגד"));
        assertEquals("דגב",ulm.getMinifiedWord("דגבא"));
        assertEquals("דגב",ulm.getMinifiedWord("דגאב"));
        assertEquals("גדב",ulm.getMinifiedWord("גאדב"));
        assertEquals("צצצ",ulm.getMinifiedWord("אקראלחדגךכלחצשכדגכצדגכשדגכשדגכצצגכשדגכצ"));
        assertEquals("דג",ulm.getMinifiedWord("דג"));
        assertEquals("",ulm.getMinifiedWord(""));
        assertEquals("י",ulm.getMinifiedWord("י"));
    }

}