Skip to main content

1578. Minimum Time to Make Rope Colorful

https://leetcode.com/problems/minimum-time-to-make-rope-colorful/

Python

Two Pointer

class Solution:
def minCost(self, colors: str, neededTime: List[int]) -> int:
cost = 0
left, right = 0, 0
while left < len(colors) and right < len(colors):
total, maximum = 0, 0
while right < len(colors) and colors[left] == colors[right]:
total += neededTime[right]
maximum = max(maximum, neededTime[right])
right += 1
cost += total - maximum
left = right
return cost