Skip to content

Commit 295c8bb

Browse files
committed
docs: implement problem description for task scheduler
1 parent 9a9f80e commit 295c8bb

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/medium/readme.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,52 @@ Put the code below in main.rs and run `cargo run`
13561356
println!("result: {}", result);
13571357
```
13581358

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
1392+
```
1393+
1394+
## How to Run in main.rs
1395+
1396+
Put the code below in main.rs and run `cargo run`
1397+
1398+
```rust
1399+
let tasks = vec!['A', 'A', 'A', 'B', 'B', 'B'];
1400+
let n = 2;
1401+
let result = leetcode::medium::task_scheduler::least_interval(tasks, n);
1402+
println!("result: {}", result);
1403+
```
1404+
13591405
# 739. Daily Temperatures
13601406

13611407
## Description

0 commit comments

Comments
 (0)