2391. Minimum Amount of Time to Collect Garbage Medium
1/**
2 * [2391] Minimum Amount of Time to Collect Garbage
3 *
4 * You are given a 0-indexed array of strings garbage where garbage[i] represents the assortment of garbage at the i^th house. garbage[i] consists only of the characters 'M', 'P' and 'G' representing one unit of metal, paper and glass garbage respectively. Picking up one unit of any type of garbage takes 1 minute.
5 * You are also given a 0-indexed integer array travel where travel[i] is the number of minutes needed to go from house i to house i + 1.
6 * There are three garbage trucks in the city, each responsible for picking up one type of garbage. Each garbage truck starts at house 0 and must visit each house in order; however, they do not need to visit every house.
7 * Only one garbage truck may be used at any given moment. While one truck is driving or picking up garbage, the other two trucks cannot do anything.
8 * Return the minimum number of minutes needed to pick up all the garbage.
9 *
10 * Example 1:
11 *
12 * Input: garbage = ["G","P","GP","GG"], travel = [2,4,3]
13 * Output: 21
14 * Explanation:
15 * The paper garbage truck:
16 * 1. Travels from house 0 to house 1
17 * 2. Collects the paper garbage at house 1
18 * 3. Travels from house 1 to house 2
19 * 4. Collects the paper garbage at house 2
20 * Altogether, it takes 8 minutes to pick up all the paper garbage.
21 * The glass garbage truck:
22 * 1. Collects the glass garbage at house 0
23 * 2. Travels from house 0 to house 1
24 * 3. Travels from house 1 to house 2
25 * 4. Collects the glass garbage at house 2
26 * 5. Travels from house 2 to house 3
27 * 6. Collects the glass garbage at house 3
28 * Altogether, it takes 13 minutes to pick up all the glass garbage.
29 * Since there is no metal garbage, we do not need to consider the metal garbage truck.
30 * Therefore, it takes a total of 8 + 13 = 21 minutes to collect all the garbage.
31 *
32 * Example 2:
33 *
34 * Input: garbage = ["MMM","PGM","GP"], travel = [3,10]
35 * Output: 37
36 * Explanation:
37 * The metal garbage truck takes 7 minutes to pick up all the metal garbage.
38 * The paper garbage truck takes 15 minutes to pick up all the paper garbage.
39 * The glass garbage truck takes 15 minutes to pick up all the glass garbage.
40 * It takes a total of 7 + 15 + 15 = 37 minutes to collect all the garbage.
41 *
42 *
43 * Constraints:
44 *
45 * 2 <= garbage.length <= 10^5
46 * garbage[i] consists of only the letters 'M', 'P', and 'G'.
47 * 1 <= garbage[i].length <= 10
48 * travel.length == garbage.length - 1
49 * 1 <= travel[i] <= 100
50 *
51 */
52pub struct Solution {}
53
54// problem: https://leetcode.com/problems/minimum-amount-of-time-to-collect-garbage/
55// discuss: https://leetcode.com/problems/minimum-amount-of-time-to-collect-garbage/discuss/?currentPage=1&orderBy=most_votes&query=
56
57// submission codes start here
58
59impl Solution {
60 pub fn garbage_collection(garbage: Vec<String>, travel: Vec<i32>) -> i32 {
61 0
62 }
63}
64
65// submission codes end
66
67#[cfg(test)]
68mod tests {
69 use super::*;
70
71 #[test]
72 fn test_2391() {
73 }
74}
75
Back
© 2025 bowen.ge All Rights Reserved.