|
| 1 | +/** |
| 2 | + * [1986] Minimum Number of Work Sessions to Finish the Tasks |
| 3 | + * |
| 4 | + * There are n tasks assigned to you. The task times are represented as an integer array tasks of length n, where the i^th task takes tasks[i] hours to finish. A work session is when you work for at most sessionTime consecutive hours and then take a break. |
| 5 | + * You should finish the given tasks in a way that satisfies the following conditions: |
| 6 | + * |
| 7 | + * If you start a task in a work session, you must complete it in the same work session. |
| 8 | + * You can start a new task immediately after finishing the previous one. |
| 9 | + * You may complete the tasks in any order. |
| 10 | + * |
| 11 | + * Given tasks and sessionTime, return the minimum number of work sessions needed to finish all the tasks following the conditions above. |
| 12 | + * The tests are generated such that sessionTime is greater than or equal to the maximum element in tasks[i]. |
| 13 | + * |
| 14 | + * Example 1: |
| 15 | + * |
| 16 | + * Input: tasks = [1,2,3], sessionTime = 3 |
| 17 | + * Output: 2 |
| 18 | + * Explanation: You can finish the tasks in two work sessions. |
| 19 | + * - First work session: finish the first and the second tasks in 1 + 2 = 3 hours. |
| 20 | + * - Second work session: finish the third task in 3 hours. |
| 21 | + * |
| 22 | + * Example 2: |
| 23 | + * |
| 24 | + * Input: tasks = [3,1,3,1,1], sessionTime = 8 |
| 25 | + * Output: 2 |
| 26 | + * Explanation: You can finish the tasks in two work sessions. |
| 27 | + * - First work session: finish all the tasks except the last one in 3 + 1 + 3 + 1 = 8 hours. |
| 28 | + * - Second work session: finish the last task in 1 hour. |
| 29 | + * |
| 30 | + * Example 3: |
| 31 | + * |
| 32 | + * Input: tasks = [1,2,3,4,5], sessionTime = 15 |
| 33 | + * Output: 1 |
| 34 | + * Explanation: You can finish all the tasks in one work session. |
| 35 | + * |
| 36 | + * |
| 37 | + * Constraints: |
| 38 | + * |
| 39 | + * n == tasks.length |
| 40 | + * 1 <= n <= 14 |
| 41 | + * 1 <= tasks[i] <= 10 |
| 42 | + * max(tasks[i]) <= sessionTime <= 15 |
| 43 | + * |
| 44 | + */ |
| 45 | +pub struct Solution {} |
| 46 | + |
| 47 | +// problem: https://leetcode.com/problems/minimum-number-of-work-sessions-to-finish-the-tasks/ |
| 48 | +// discuss: https://leetcode.com/problems/minimum-number-of-work-sessions-to-finish-the-tasks/discuss/?currentPage=1&orderBy=most_votes&query= |
| 49 | + |
| 50 | +// submission codes start here |
| 51 | + |
| 52 | +impl Solution { |
| 53 | + pub fn min_sessions(tasks: Vec<i32>, session_time: i32) -> i32 { |
| 54 | + 0 |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +// submission codes end |
| 59 | + |
| 60 | +#[cfg(test)] |
| 61 | +mod tests { |
| 62 | + use super::*; |
| 63 | + |
| 64 | + #[test] |
| 65 | + #[ignore] |
| 66 | + fn test_1986_example_1() { |
| 67 | + let tasks = vec![1, 2, 3]; |
| 68 | + let session_time = 3; |
| 69 | + |
| 70 | + let result = 2; |
| 71 | + |
| 72 | + assert_eq!(Solution::min_sessions(tasks, session_time), result); |
| 73 | + } |
| 74 | + |
| 75 | + #[test] |
| 76 | + #[ignore] |
| 77 | + fn test_1986_example_2() { |
| 78 | + let tasks = vec![3, 1, 3, 1, 1]; |
| 79 | + let session_time = 8; |
| 80 | + |
| 81 | + let result = 2; |
| 82 | + |
| 83 | + assert_eq!(Solution::min_sessions(tasks, session_time), result); |
| 84 | + } |
| 85 | + |
| 86 | + #[test] |
| 87 | + #[ignore] |
| 88 | + fn test_1986_example_3() { |
| 89 | + let tasks = vec![1, 2, 3, 4, 5]; |
| 90 | + let session_time = 15; |
| 91 | + |
| 92 | + let result = 1; |
| 93 | + |
| 94 | + assert_eq!(Solution::min_sessions(tasks, session_time), result); |
| 95 | + } |
| 96 | +} |
0 commit comments