Medium · Greedy

Minimum Time to Make Rope Colorful

Given an ASCII color string colors and an array neededTime of the same length, where balloon i has color colors[i] and takes neededTime[i] to remove, return the minimum total time to remove balloons so that no two adjacent remaining balloons share a color.

Examples

Example 1

{
  "colors": "aabaa",
  "neededTime": [1, 2, 3, 4, 1]
}

Output: min time = 2

Example 2

{
  "colors": "abc",
  "neededTime": [1, 2, 3]
}

Output: min time = 0

Rebuild it in the studio

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Greedy problems