Java || Priority Queue || Hash Map Implementation
\nclass Element {\n    char letter;\n    int frequency;\n    Element(char letter, int frequency) {\n        this.letter = letter;\n        this.frequency = freq
```\nclass Element {\n    char letter;\n    int frequency;\n    Element(char letter, int frequency) {\n        this.letter = letter;\n        this.frequency = frequency;\n    }\n}\n\nclass ElementComparator implements Comparator<Element> {\n    @Override\n    public int compare(Element e1, Element e2) {\n        return Character.compare(e2.letter, e1.letter);\n    }\n}\n\nclass Solution {\n    public String repeatLimitedString(String s, int repeatLimit) {\n        PriorityQueue<Element> maxHeap = new PriorityQueue<>(new ElementComparator());\n        Map<Character, Integer> freqMap = new HashMap<>();\n        for(char letter: s.toCharArray()) {\n           freqMap.put(letter, freqMap.getOrDefault(letter, 0) + 1); \n        }\n        for(Map.Entry<Character, Integer> entry: freqMap.entrySet()) {\n            maxHeap.offer(new Element(entry.getKey(), entry.getValue()));\n        }\n        StringBuilder answer = new StringBuilder();\n        while(!maxHeap.isEmpty()) {\n            Element element = maxHeap.poll();\n            for(int i=0;i<repeatLimit;i++) {\n                answer.append(element.letter);\n                element.frequency--;\n                if(element.frequency == 0) {\n                    break;\n                }\n            }\n            if(element.frequency != 0) {\n                if(!maxHeap.isEmpty()) {\n                    Element next = maxHeap.poll();\n                    answer.append(next.letter);\n                    next.frequency--;\n                    if(next.frequency != 0) {\n                        maxHeap.offer(next);\n                    }\n                    maxHeap.offer(element);\n                }\n            }\n        }\n        return answer.toString();\n    }\n}\n```
['Heap (Priority Queue)', 'Java']