2365. Task Scheduler II Medium
1/**
2 * [2365] Task Scheduler II
3 *
4 * You are given a 0-indexed array of positive integers tasks, representing tasks that need to be completed in order, where tasks[i] represents the type of the i^th task.
5 * You are also given a positive integer space, which represents the minimum number of days that must pass after the completion of a task before another task of the same type can be performed.
6 * Each day, until all tasks have been completed, you must either:
7 *
8 * Complete the next task from tasks, or
9 * Take a break.
10 *
11 * Return the minimum number of days needed to complete all tasks.
12 *
13 * Example 1:
14 *
15 * Input: tasks = [1,2,1,2,3,1], space = 3
16 * Output: 9
17 * Explanation:
18 * One way to complete all tasks in 9 days is as follows:
19 * Day 1: Complete the 0th task.
20 * Day 2: Complete the 1st task.
21 * Day 3: Take a break.
22 * Day 4: Take a break.
23 * Day 5: Complete the 2nd task.
24 * Day 6: Complete the 3rd task.
25 * Day 7: Take a break.
26 * Day 8: Complete the 4th task.
27 * Day 9: Complete the 5th task.
28 * It can be shown that the tasks cannot be completed in less than 9 days.
29 *
30 * Example 2:
31 *
32 * Input: tasks = [5,8,8,5], space = 2
33 * Output: 6
34 * Explanation:
35 * One way to complete all tasks in 6 days is as follows:
36 * Day 1: Complete the 0th task.
37 * Day 2: Complete the 1st task.
38 * Day 3: Take a break.
39 * Day 4: Take a break.
40 * Day 5: Complete the 2nd task.
41 * Day 6: Complete the 3rd task.
42 * It can be shown that the tasks cannot be completed in less than 6 days.
43 *
44 *
45 * Constraints:
46 *
47 * 1 <= tasks.length <= 10^5
48 * 1 <= tasks[i] <= 10^9
49 * 1 <= space <= tasks.length
50 *
51 */
52pub struct Solution {}
53
54// problem: https://leetcode.com/problems/task-scheduler-ii/
55// discuss: https://leetcode.com/problems/task-scheduler-ii/discuss/?currentPage=1&orderBy=most_votes&query=
56
57// submission codes start here
58
59impl Solution {
60 pub fn task_scheduler_ii(tasks: Vec<i32>, space: i32) -> i64 {
61
62 }
63}
64
65// submission codes end
66
67#[cfg(test)]
68mod tests {
69 use super::*;
70
71 #[test]
72 fn test_2365() {
73 }
74}
75
Back
© 2025 bowen.ge All Rights Reserved.