File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ Given a characters array tasks, representing the tasks a CPU needs to do, where each letter represents a different task.
3+ Tasks could be done in any order. Each task is done in one unit of time. For each unit of time,
4+ the CPU could complete either one task or just be idle.
5+
6+ However, there is a non-negative integer n that represents the cooldown period between
7+ two same tasks (the same letter in the array),
8+ is that there must be at least n units of time between any two same tasks.
9+
10+
11+ Memory ->14.4MB
12+ runtime ->412ms
13+
14+
15+
16+
17+ """
18+
19+
20+ class Solution :
21+ def leastInterval (self , tasks : List [str ], n : int ) -> int :
22+ counter = Counter (tasks )
23+ freq = sorted (list (counter .values ()))
24+
25+ max_idle = freq .pop ()
26+ total = (max_idle - 1 )* n
27+
28+ while freq and total > 0 :
29+ total = total - min (max_idle - 1 ,freq .pop ())
30+
31+ total = max (0 ,total )
32+ return len (tasks ) + total
Original file line number Diff line number Diff line change @@ -189,6 +189,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
189189| --- | ------------------------------------------------------------------------------- | --------------------------------------- | ------ | ------ | ---------- | --------------------- | ---- |
190190| 933 | [ Number of Recent Calls] ( https://leetcode.com/problems/number-of-recent-calls/ ) | [ C++] ( ./C++/Number-of-Recent-Calls.cpp ) | _ O(1)_ | _ O(1)_ | Easy | Queue, Sliding Window |
191191| 641 | [ Design Circular Deque] ( https://leetcode.com/problems/design-circular-deque/ ) | [ Java] ( ./Java/design-circular-deque.java/ ) | _ O(n)_ | _ O(n)_ | Medium | Queue, Design |
192+ | 621 | [ Task Scheduler ] ( https://leetcode.com/problems/task-scheduler/ ) | [ Python] ( ./Python/621-Task-Scheduler.py/ ) | _ O(n)_ | _ O(n)_ | Medium | Queue
192193
193194<br />
194195<div align =" right " >
You can’t perform that action at this time.
0 commit comments