Tap here to switch tabs
Problem
Submissions

Problem: Maximum Score From Removing Substrings

med
30 min
Try to solve the Maximum Score From Removing Substrings problem.

Statement

You are given a string s and two integers x and y. You can perform two types of operations any number of times:

  1. Remove any occurrence of the substring "ab" and gain x points.

  2. Remove any occurrence of the substring "ba" and gain y points.

Return the maximum total points you can obtain after applying any number of these operations.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • 1≤1 \leq x, y ≤104\leq 10^4

  • s consists of lowercase English letters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Score From Removing Substrings

med
30 min
Try to solve the Maximum Score From Removing Substrings problem.

Statement

You are given a string s and two integers x and y. You can perform two types of operations any number of times:

  1. Remove any occurrence of the substring "ab" and gain x points.

  2. Remove any occurrence of the substring "ba" and gain y points.

Return the maximum total points you can obtain after applying any number of these operations.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • 1≤1 \leq x, y ≤104\leq 10^4

  • s consists of lowercase English letters.