prefixSum
with the same length as travel
plus one, with prefixSum[0]
set to 0.prefixSum
array with the cumulative sum of the travel
array.garbageLastPos
to store the last position of each type of garbage.totalGarbage
to count the total units of garbage.garbage
array, updating garbageLastPos
with the last position of each type of garbage and incrementing totalGarbage
by the length of each string in garbage
.totalGarbage
.totalGarbage
as the total time required.