|
| 1 | +<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <li>Remove substring <code>"ab"</code> and gain <code>x</code> points. |
| 5 | + |
| 6 | + <ul> |
| 7 | + <li>For example, when removing <code>"ab"</code> from <code>"c<u>ab</u>xbae"</code> it becomes <code>"cxbae"</code>.</li> |
| 8 | + </ul> |
| 9 | + </li> |
| 10 | + <li>Remove substring <code>"ba"</code> and gain <code>y</code> points. |
| 11 | + <ul> |
| 12 | + <li>For example, when removing <code>"ba"</code> from <code>"cabx<u>ba</u>e"</code> it becomes <code>"cabxe"</code>.</li> |
| 13 | + </ul> |
| 14 | + </li> |
| 15 | +</ul> |
| 16 | + |
| 17 | +<p>Return <em>the maximum points you can gain after applying the above operations on</em> <code>s</code>.</p> |
| 18 | + |
| 19 | +<p> </p> |
| 20 | +<p><strong class="example">Example 1:</strong></p> |
| 21 | + |
| 22 | +<pre> |
| 23 | +<strong>Input:</strong> s = "cdbcbbaaabab", x = 4, y = 5 |
| 24 | +<strong>Output:</strong> 19 |
| 25 | +<strong>Explanation:</strong> |
| 26 | +- Remove the "ba" underlined in "cdbcbbaaa<u>ba</u>b". Now, s = "cdbcbbaaab" and 5 points are added to the score. |
| 27 | +- Remove the "ab" underlined in "cdbcbbaa<u>ab</u>". Now, s = "cdbcbbaa" and 4 points are added to the score. |
| 28 | +- Remove the "ba" underlined in "cdbcb<u>ba</u>a". Now, s = "cdbcba" and 5 points are added to the score. |
| 29 | +- Remove the "ba" underlined in "cdbc<u>ba</u>". Now, s = "cdbc" and 5 points are added to the score. |
| 30 | +Total score = 5 + 4 + 5 + 5 = 19.</pre> |
| 31 | + |
| 32 | +<p><strong class="example">Example 2:</strong></p> |
| 33 | + |
| 34 | +<pre> |
| 35 | +<strong>Input:</strong> s = "aabbaaxybbaabb", x = 5, y = 4 |
| 36 | +<strong>Output:</strong> 20 |
| 37 | +</pre> |
| 38 | + |
| 39 | +<p> </p> |
| 40 | +<p><strong>Constraints:</strong></p> |
| 41 | + |
| 42 | +<ul> |
| 43 | + <li><code>1 <= s.length <= 10<sup>5</sup></code></li> |
| 44 | + <li><code>1 <= x, y <= 10<sup>4</sup></code></li> |
| 45 | + <li><code>s</code> consists of lowercase English letters.</li> |
| 46 | +</ul> |
0 commit comments