def minCost(self, colors: str, neededTime: List[int]) -> int:
ans = 0
maxNeededTime = neededTime
for i in range(1, len(colors)):
if colors[i] == colors[i - 1]:
ans += min(maxNeededTime, neededTime[i])
# For each continuous group, Bob needs to remove every balloon except
# the one with the max `neededTime`. So, he should hold the balloon
# with the highest `neededTime` in his hand.
maxNeededTime = max(maxNeededTime, neededTime[i])
# If the current balloon is different from the previous one, discard
# the balloon from the previous group and hold the new one in hand.
maxNeededTime = neededTime[i]