-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay 28
More file actions
27 lines (19 loc) · 721 Bytes
/
Day 28
File metadata and controls
27 lines (19 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#1578.minimum-time-to-make-rope-colorful:-
class Solution:
def minCost(self, colors: str, neededTime: List[int]) -> int:
total_time = 0
i = 0
n = len(colors)
while i < n:
j = i
group_sum = 0
group_max = 0
# Traverse the group of same color
while j < n and colors[j] == colors[i]:
group_sum += neededTime[j]
group_max = max(group_max, neededTime[j])
j += 1
# Remove all except one (max time one stays)
total_time += (group_sum - group_max)
i = j # move to next group
return total_time