shlogg · Early preview
Md Ariful Haque @mah-shamim

Maximum Score From Removing Substrings In PHP

Maximum points from removing substrings "ab" and "ba". Use stack to process string, prioritize higher value removals. Return max points after applying operations on s.

1717. Maximum Score From Removing Substrings
Medium
You are given a string s and two integers x and y. You can perform two types of operations any number of times.

Remove substring "ab" and gain x points.

For example, when removing "ab" from "cabxbae" it becomes "cxbae".


Remove substring "ba" and gain y points.

For example, when removing "ba" from "cabxbae" it becomes "cabxe".



Return the maximum points you can gain after applying the above operations on s.
Example 1:

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

Remove the "ba" underlined in "cdbcbbaaabab". Now, s =...