You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/medium/readme.md
+46Lines changed: 46 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1356,6 +1356,52 @@ Put the code below in main.rs and run `cargo run`
1356
1356
println!("result: {}", result);
1357
1357
```
1358
1358
1359
+
# 621. Task Scheduler
1360
+
1361
+
## Description
1362
+
1363
+
Given a characters array tasks, representing the tasks a CPU needs to do, where each letter represents a different task. Tasks could be done in any order. Each task is done in one unit of time. For each unit of time, the CPU could complete either one task or just be idle.
1364
+
1365
+
However, there is a non-negative integer n that represents the cooldown period between two same tasks (the same letter in the array), that is that there must be at least n units of time between any two same tasks.
1366
+
1367
+
Return the least number of units of times that the CPU will take to finish all the given tasks.
1368
+
1369
+
## Examples
1370
+
1371
+
```text
1372
+
Input: tasks = ["A","A","A","B","B","B"], n = 2
1373
+
Output: 8
1374
+
Explanation:
1375
+
A -> B -> idle -> A -> B -> idle -> A -> B
1376
+
There is at least 2 units of time between any two same tasks.
1377
+
1378
+
Input: tasks = ["A","A","A","B","B","B"], n = 0
1379
+
Output: 6
1380
+
Explanation: On this case any permutation of size 6 would work since n = 0.
1381
+
["A","A","A","B","B","B"]
1382
+
["A","B","A","B","A","B"]
1383
+
["B","B","B","A","A","A"]
1384
+
...
1385
+
And so on.
1386
+
1387
+
Input: tasks = ["A","A","A","A","A","A","B","C","D","E","F","G"], n = 2
1388
+
Output: 16
1389
+
Explanation:
1390
+
One possible solution is
1391
+
A -> B -> C -> A -> D -> E -> A -> F -> G -> A -> idle -> idle -> A -> idle -> idle -> A
0 commit comments