java.lang.Object
g1701_1800.s1717_maximum_score_from_removing_substrings.Solution

public class Solution extends Object
1717 - Maximum Score From Removing Substrings.<p>Medium</p> <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> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <code>&quot;cabxbae&quot;</code> it becomes <code>&quot;cxbae&quot;</code>.</li> </ul> </li> <li>Remove substring <code>&quot;ba&quot;</code> and gain <code>y</code> points. <ul> <li>For example, when removing <code>&quot;ba&quot;</code> from <code>&quot;cabxbae&quot;</code> it becomes <code>&quot;cabxe&quot;</code>.</li> </ul> </li> </ul> <p>Return <em>the maximum points you can gain after applying the above operations on</em> <code>s</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;cdbcbbaaabab&rdquo;, x = 4, y = 5</p> <p><strong>Output:</strong> 19</p> <p><strong>Explanation:</strong></p> <ul> <li> <p>Remove the &ldquo;ba&rdquo; underlined in &ldquo;cdbcbbaaabab&rdquo;. Now, s = &ldquo;cdbcbbaaab&rdquo; and 5 points are added to the score.</p> </li> <li> <p>Remove the &ldquo;ab&rdquo; underlined in &ldquo;cdbcbbaaab&rdquo;. Now, s = &ldquo;cdbcbbaa&rdquo; and 4 points are added to the score.</p> </li> <li> <p>Remove the &ldquo;ba&rdquo; underlined in &ldquo;cdbcbbaa&rdquo;. Now, s = &ldquo;cdbcba&rdquo; and 5 points are added to the score. - Remove the &ldquo;ba&rdquo; underlined in &ldquo;cdbcba&rdquo;. Now, s = &ldquo;cdbc&rdquo; and 5 points are added to the score. Total score = 5 + 4 + 5 + 5 = 19.</p> </li> </ul> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;aabbaaxybbaabb&rdquo;, x = 5, y = 4</p> <p><strong>Output:</strong> 20</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 10<sup>5</sup></code></li> <li><code>1 <= x, y <= 10<sup>4</sup></code></li> <li><code>s</code> consists of lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maximumGain

      public int maximumGain(String s, int x, int y)