Using priority queue (faster 100%)
Approach\nWe count every character and use\npriority queue to achieve lexicographical order\n\nE.g zzzzccca, repeatLimit=3\n0) we build a queue: [z:4, c:3, a:1]
# Approach\nWe count every character and use\npriority queue to achieve lexicographical order\n```\nE.g zzzzccca, repeatLimit=3\n0) we build a queue: [z:4, c:3, a:1]\n1) Start iterating a queue, on every iteration we\n  2) dequeue {z:4} \n  3) generate "zzz" (now we left with {z:1})\n  4) pick next element in a queue {c:3}, generate ONE "c", now we left with {c:2}\n  5) push {z:1} back to the queue, repeat from 2\n```\n\n\n# Complexity\n- Time complexity:\n$$O(nlogn)$$\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n```\nvar repeatLimitedString = function (s, repeatLimit) {\n  const freq = {}, \n  //https://github.com/datastructures-js/priority-queue\n  queue = new MaxPriorityQueue(), result=[];\n  for(let c of s) freq[c]=freq[c]?freq[c]+1:1;\n  for(let [k,v] of Object.entries(freq))\n    queue.enqueue({l:k, c:v}, k.charCodeAt(0)-97);\n  \n  while(!queue.isEmpty()){\n    const {element:top, priority:prior} = queue.dequeue();\n    for(let i=0; i<repeatLimit && top.c>0;i++, top.c--)\n      result.push(top.l);\n\n    if(top.c>0){\n      if(!queue.isEmpty()){\n        const f = queue.front().element;\n        result.push(f.l);\n        f.c--;\n        if(f.c===0) queue.dequeue();\n        queue.enqueue(top, prior);\n      }\n    }\n  }\n  return result.join("");\n}\n```
['JavaScript']