1
class Solution:
2
def leastInterval(self, tasks: List[str], n: int) -> int:
3
max_heap = []
4
queue = deque()
5
word_count = defaultdict(int)
6
timer = 0
7
for i in range(len(tasks)):
8
word_count[tasks[i]] += 1
9
for _ , val in word_count.items():
10
heappush(max_heap, -1*val)
11
while max_heap or queue:
12
timer += 1
13
if max_heap:
14
v = -1* heappop(max_heap)
15
v -= 1
16
if v:
17
queue.append((v, timer+n))
18
if queue and queue[0][1] == timer:
19
heappush(max_heap, -1*queue.popleft()[0])
20
return timer

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0