Skip to content

Practice Maximum Score From Removing Substrings

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1717
LeetCode Problem

Maximum Score From Removing Substrings

Problem Statement

Repeatedly remove any contiguous ab for x points or any contiguous ba for y points; removal joins the remaining characters on either side. Return the maximum total score obtainable from s after any number of removals.

Source: Maximum Score From Removing Substrings on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "cdbcbbaaabab", x = 4, y = 5
Output
19

# Example 2

Input
s = "aabbaaxybbaabb", x = 5, y = 4
Output
20

Constraints

1 <= s.length <= 10^5
1 <= x, y <= 10^4
s consists of lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Maximum Score From Removing Substrings.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.