FastPrepFastPrep
Problem Brief

Maximize Score

OA

You are given a string S and an integer array of size N. You need to maximize your score by performing the following operation multiple times until the string S is empty:

Choose a substring from S where all characters are identical.

Calculate the length of this substring, called size.

Add the sizeth element from the array arr to your total score.

Remove the selected substring from S.

Continue this process until the string S is empty, and return the maximum possible score.

1Example 1

Input
S = "abbbac", arr = [2, 5, 3, 1, 7]
Output
14
Explanation

abbbac -> abac -> aac -> c -> ""

5 + 2 + 5 + 2 = 14

Constraints

Limits and guarantees your solution can rely on.

🦡
public int maximizeScore(String s, int[] arr) {
  // write your code here
}
Input

S

"abbbac"

arr

[2, 5, 3, 1, 7]

Output

14

Sign in to submit your solution.