n − 1. House i has put out bags described by the string bins[i], where each letter is one bag: M for metal, P for paper, G for glass. An empty string means the house has nothing out. Loading one bag takes 1 minute. Driving from house i to house i + 1 takes drive[i] minutes.
Each kind of material has its own truck. Every truck starts at house 0 and only moves forward, house by house; a truck never needs to go past the last house holding its material, and if there is none of that material at all, it stays put.
Only one truck works at a time: while one is driving or loading, the others wait. Return the total number of minutes needed to collect everything.bins=['PM', 'G', 'P'], drive=[5, 2] → 16
Metal: 1 minute to load at house 0. Glass: 5 minutes of driving plus 1 to load. Paper: 1 + 5 + 2 + 1 = 9 minutes. Total 1 + 6 + 9 = 16.
bins=['GGG', 'MM', 'MG', 'G'], drive=[4, 1, 3] → 21
Glass drives all the way to house 3: 8 minutes of road and 5 units — 13. Metal stops at house 2: 5 minutes of road and 3 units — 8. There is no paper. Total 21.
bins=['MPG'], drive=[] → 3
There is only one house, so no driving: each of the three trucks spends one minute loading.
bins.length ≤ 10⁵bins[i].length ≤ 10bins[i] consists only of the letters M, P and Gdrive.length = bins.length − 1drive[i] ≤ 100bins=['PM', 'G', 'P'], drive=[5, 2]
16
Run checks the first 3 tests in your browser. Submit checks all 104 tests on the server, hidden ones included.