Easy Java Solution  ||   Priority Queue
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []

class Solution {
    public String repeatLimitedString(String s, int repeatLimit) {

        int[] freq = new int[26];

     
        for (char ch : s.toCharArray()) {
            freq[ch - 'a']++;
        }

        StringBuilder sb = new StringBuilder();
        PriorityQueue<Character> pq = new PriorityQueue<>(Collections.reverseOrder());

    
        for (int i = 25; i >= 0; i--) {
            if (freq[i] > 0) {
                  pq.add((char) (i + 'a'));
            }
        }

        while (!pq.isEmpty()) {

            char top = pq.poll(); 
            
            int count = Math.min(freq[top - 'a'], repeatLimit); 

            for (int i = 0; i < count; i++) {
                sb.append(top);
            }

            freq[top - 'a'] -= count;

            if (freq[top - 'a'] > 0) {
                
              if (pq.isEmpty()) break; 

                char next = pq.poll(); 
                sb.append(next);
                freq[next - 'a']--;

                if (freq[next - 'a'] > 0) {
                    pq.add(next); 
                }
 
                 pq.add(top); 
            }
        }


        return sb.toString();
    }
}

```
['Java']