1
from heapq import heapify, heappush, heappop2
from collections import defaultdict6
def repeatLimitedString(self, string: str, k: int) -> str:8
look close to the problem:9
it's lexicographically largest12
appear, times = defaultdict(), defaultdict()15
appear[s] = appear.get(s, 0) + 118
pq.append((-ord(s), appear[s]))24
char, num = heappop(pq)26
if s in times and times[s] == k: # if reach the repeatedLimit29
char2, num2 = heappop(pq)33
heappush(pq, (char2, num2 - 1))34
heappush(pq, (char, num))38
if stack and stack[-1] != s:42
times[s] = times.get(s, 0) + 145
heappush(pq, (char, num - 1))