Loading...
You are given a string s of lowercase English letters and two integers pointsAB and pointsBA. You may repeatedly apply either operation, any number of times and in any order:
"ab" and gain pointsAB points."ba" and gain pointsBA points.Removing a substring joins the characters on its two sides, which may create new removable substrings.
Return the maximum total points you can gain.
Input: s = "cdbcbbaaabab", pointsAB = 4, pointsBA = 5
Output: 19
Explanation: Removing "ba" occurrences (5 points each) before "ab"
occurrences (4 points each) yields the maximum of 19 points.
Input: s = "aabbaaxybbaabb", pointsAB = 5, pointsBA = 4
Output: 20
Explanation: Removing "ab" occurrences (5 points each) first is optimal here,
for a total of 20 points.
s.length ≤105pointsAB, pointsBA ≤104s consists of lowercase English letters.Click "Run" to test with sample cases or "Submit" to run all tests.