Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    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.

    • Remove substring "ba" and gain y points.

    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 = "cdbcbbaaab" and 5 points are added to the score.

    • Remove the "ab" underlined in "cdbcbbaaab". Now, s = "cdbcbbaa" and 4 points are added to the score.

    • Remove the "ba" underlined in "cdbcbbaa". Now, s = "cdbcba" and 5 points are added to the score. - Remove the "ba" underlined in "cdbcba". Now, s = "cdbc" and 5 points are added to the score. Total score = 5 + 4 + 5 + 5 = 19.

    Example 2:

    Input: s = "aabbaaxybbaabb", x = 5, y = 4

    Output: 20

    Constraints:

    • <code>1 <= s.length <= 10<sup>5</sup></code>

    • <code>1 <= x, y <= 10<sup>4</sup></code>

    • s consists of lowercase English letters.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer maximumGain(String s, Integer x, Integer y)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait