The Minimum Amount of Time to Collect Garbage problem features a neighborhood where different houses have three types of garbage: Metal (M), Paper (P), and Glass (G). You have three specialized trucks, one for each type. Each truck starts at house 0 and must collect all garbage of its specific type. You are given the amount of garbage at each house and the travel time between consecutive houses. The goal is to find the total time spent by all three trucks combined.
This is a standard Minimum Amount of Time to Collect Garbage interview question at companies like Microsoft and Amazon. It tests a candidate's ability to simplify a seemingly complex simulation. While it sounds like you need to simulate three separate routes, the core logic relies on identifying the last house each truck needs to visit. It evaluates efficiency in iterating through arrays and managing cumulative sums.
The Prefix Sum interview pattern and a "Last Occurrence" tracking strategy are most effective here.
Garbage: ["G", "P", "GP", "GG"], Travel: [2, 4, 3].
2 + 4 + 3 = 9.2 + 4 = 6.0.6 (collection) + 9 (G travel) + 6 (P travel) = 21 minutes.When a problem involves multiple "agents" (like trucks) moving along the same path, ask if their actions are independent. Here, the trucks don't interfere with each other, so you can calculate their costs separately and sum them up. This Array interview pattern is common in logistics-style questions.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Minimum Number of Operations to Move All Balls to Each Box | Medium | Solve | |
| Count Vowel Strings in Ranges | Medium | Solve | |
| Shifting Letters | Medium | Solve | |
| Shifting Letters II | Medium | Solve | |
| Shift Distance Between Two Strings | Medium | Solve |