leetcode.com Open in urlscan Pro
2606:4700:20::681a:965  Public Scan

URL: https://leetcode.com/problems/minimum-time-to-make-rope-colorful/description/?envtype=daily-question&envid=2023-12-27
Submission: On December 27 via api from US — Scanned from DE

Form analysis 0 forms found in the DOM

Text Content

Problem List
Problem List



Premium
RegisterorSign in
Description


Editorial
Solutions (3.3K)
Submissions
1578. Minimum Time to Make Rope Colorful


Medium
3.3K
103


Companies

Alice has n balloons arranged on a rope. You are given a 0-indexed string colors
where colors[i] is the color of the ith balloon.

Alice wants the rope to be colorful. She does not want two consecutive balloons
to be of the same color, so she asks Bob for help. Bob can remove some balloons
from the rope to make it colorful. You are given a 0-indexed integer array
neededTime where neededTime[i] is the time (in seconds) that Bob needs to remove
the ith balloon from the rope.

Return the minimum time Bob needs to make the rope colorful.

 

Example 1:

Input: colors = "abaac", neededTime = [1,2,3,4,5]
Output: 3
Explanation: In the above image, 'a' is blue, 'b' is red, and 'c' is green.
Bob can remove the blue balloon at index 2. This takes 3 seconds.
There are no longer two consecutive balloons of the same color. Total time = 3.

Example 2:

Input: colors = "abc", neededTime = [1,2,3]
Output: 0
Explanation: The rope is already colorful. Bob does not need to remove any balloons from the rope.


Example 3:

Input: colors = "aabaa", neededTime = [1,2,3,4,1]
Output: 2
Explanation: Bob will remove the ballons at indices 0 and 4. Each ballon takes 1 second to remove.
There are no longer two consecutive balloons of the same color. Total time = 1 + 1 = 2.


 

Constraints:

 * n == colors.length == neededTime.length
 * 1 <= n <= 105
 * 1 <= neededTime[i] <= 104
 * colors contains only lowercase English letters.


Accepted
195.5K

Submissions
308K

Acceptance Rate
63.5%

--------------------------------------------------------------------------------

Discussion (74)



--------------------------------------------------------------------------------

Related Topics

ArrayStringDynamic ProgrammingGreedy
Copyright ©️ 2023 LeetCode All rights reserved

C++


Auto

1
2
3
4
5
6
class Solution {
public:
    int minCost(string colors, vector<int>& neededTime) {
        
    }
};










Saved to local
Ln 1, Col 1
You need to Login / Sign up to run or submit


LeetWizBeta

Why am I getting this error?

Analyzing code...
Console


RunSubmit





word word word word word word word word word word word word word word word word
word word word word word word word word word word word word word word word word
word word word word word word word word word word word word word word word word
word word word word word word word word word word word word word word word word
word word word word word word word word word word word word word word word word
word word word word word word word word word word word word word word word word
word word word word word word word word word word word word word word word word
word word word word word word word word word word word word word word word word
word word word word word word word word word word word word word word word word
word word word word word word word word word word word word word word word word
word word word word word word word word word word word word word word word word
word word word word word word word word word word word word word word word word
word word word word word word word word

mmMwWLliI0fiflO&1
mmMwWLliI0fiflO&1
mmMwWLliI0fiflO&1
mmMwWLliI0fiflO&1
mmMwWLliI0fiflO&1
mmMwWLliI0fiflO&1
mmMwWLliI0fiflO&1