2589. Minimum Time to Complete All Tasks Hard

@problem@discussion
#Array#Binary Search#Stack#Greedy#Sorting



1/**
2 * [2589] Minimum Time to Complete All Tasks
3 *
4 * There is a computer that can run an unlimited number of tasks at the same time. You are given a 2D integer array tasks where tasks[i] = [starti, endi, durationi] indicates that the i^th task should run for a total of durationi seconds (not necessarily continuous) within the inclusive time range [starti, endi].
5 * You may turn on the computer only when it needs to run a task. You can also turn it off if it is idle.
6 * Return the minimum time during which the computer should be turned on to complete all tasks.
7 *  
8 * <strong class="example">Example 1:
9 * 
10 * Input: tasks = [[2,3,1],[4,5,1],[1,5,2]]
11 * Output: 2
12 * Explanation: 
13 * - The first task can be run in the inclusive time range [2, 2].
14 * - The second task can be run in the inclusive time range [5, 5].
15 * - The third task can be run in the two inclusive time ranges [2, 2] and [5, 5].
16 * The computer will be on for a total of 2 seconds.
17 * 
18 * <strong class="example">Example 2:
19 * 
20 * Input: tasks = [[1,3,2],[2,5,3],[5,6,2]]
21 * Output: 4
22 * Explanation: 
23 * - The first task can be run in the inclusive time range [2, 3].
24 * - The second task can be run in the inclusive time ranges [2, 3] and [5, 5].
25 * - The third task can be run in the two inclusive time range [5, 6].
26 * The computer will be on for a total of 4 seconds.
27 * 
28 *  
29 * Constraints:
30 * 
31 * 	1 <= tasks.length <= 2000
32 * 	tasks[i].length == 3
33 * 	1 <= starti, endi <= 2000
34 * 	1 <= durationi <= endi - starti + 1 
35 * 
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/minimum-time-to-complete-all-tasks/
40// discuss: https://leetcode.com/problems/minimum-time-to-complete-all-tasks/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45    pub fn find_minimum_time(tasks: Vec<Vec<i32>>) -> i32 {
46        0
47    }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_2589() {
58    }
59}
60


Back
© 2025 bowen.ge All Rights Reserved.