Class Solution
java.lang.Object
g2201_2300.s2207_maximize_number_of_subsequences_in_a_string.Solution
2207 - Maximize Number of Subsequences in a String.<p>Medium</p>
<p>You are given a <strong>0-indexed</strong> string <code>text</code> and another <strong>0-indexed</strong> string <code>pattern</code> of length <code>2</code>, both of which consist of only lowercase English letters.</p>
<p>You can add <strong>either</strong> <code>pattern[0]</code> <strong>or</strong> <code>pattern[1]</code> anywhere in <code>text</code> <strong>exactly once</strong>. Note that the character can be added even at the beginning or at the end of <code>text</code>.</p>
<p>Return <em>the <strong>maximum</strong> number of times</em> <code>pattern</code> <em>can occur as a <strong>subsequence</strong> of the modified</em> <code>text</code>.</p>
<p>A <strong>subsequence</strong> is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> text = “abdcdbc”, pattern = “ac”</p>
<p><strong>Output:</strong> 4</p>
<p><strong>Explanation:</strong></p>
<p>If we add pattern[0] = ‘a’ in between text[1] and text[2], we get “ab<strong>a</strong>dcdbc”. Now, the number of times “ac” occurs as a subsequence is 4.</p>
<p>Some other strings which have 4 subsequences “ac” after adding a character to text are “<strong>a</strong>abdcdbc” and “abd<strong>a</strong>cdbc”.</p>
<p>However, strings such as “abdc<strong>a</strong>dbc”, “abd<strong>c</strong>cdbc”, and “abdcdbc<strong>c</strong>”, although obtainable, have only 3 subsequences “ac” and are thus suboptimal.</p>
<p>It can be shown that it is not possible to get more than 4 subsequences “ac” by adding only one character.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> text = “aabb”, pattern = “ab”</p>
<p><strong>Output:</strong> 6</p>
<p><strong>Explanation:</strong></p>
<p>Some of the strings which can be obtained from text and have 6 subsequences “ab” are “<strong>a</strong>aabb”, “aa<strong>a</strong>bb”, and “aab<strong>b</strong>b”.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= text.length <= 10<sup>5</sup></code></li>
<li><code>pattern.length == 2</code></li>
<li><code>text</code> and <code>pattern</code> consist only of lowercase English letters.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maximumSubsequenceCount
-