Class Solution
java.lang.Object
g2001_2100.s2030_smallest_k_length_subsequence_with_occurrences_of_a_letter.Solution
2030 - Smallest K-Length Subsequence With Occurrences of a Letter.<p>Hard</p>
<p>You are given a string <code>s</code>, an integer <code>k</code>, a letter <code>letter</code>, and an integer <code>repetition</code>.</p>
<p>Return <em>the <strong>lexicographically smallest</strong> subsequence of</em> <code>s</code> <em>of length</em> <code>k</code> <em>that has the letter</em> <code>letter</code> <em>appear <strong>at least</strong></em> <code>repetition</code> <em>times</em>. The test cases are generated so that the <code>letter</code> appears in <code>s</code> <strong>at least</strong> <code>repetition</code> times.</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>A string <code>a</code> is <strong>lexicographically smaller</strong> than a string <code>b</code> if in the first position where <code>a</code> and <code>b</code> differ, string <code>a</code> has a letter that appears earlier in the alphabet than the corresponding letter in <code>b</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> s = “leet”, k = 3, letter = “e”, repetition = 1</p>
<p><strong>Output:</strong> “eet”</p>
<p><strong>Explanation:</strong> There are four subsequences of length 3 that have the letter ‘e’ appear at least 1 time:</p>
<ul>
<li>
<p>“lee” (from “<strong>lee</strong>t”)</p>
</li>
<li>
<p>“let” (from “<strong>le</strong>e<strong>t</strong>”)</p>
</li>
<li>
<p>“let” (from “<strong>l</strong>e<strong>et</strong>”)</p>
</li>
<li>
<p>“eet” (from “l<strong>eet</strong>”)</p>
</li>
</ul>
<p>The lexicographically smallest subsequence among them is “eet”.</p>
<p><strong>Example 2:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/09/13/smallest-k-length-subsequence.png" alt="example-2" /></p>
<p><strong>Input:</strong> s = “leetcode”, k = 4, letter = “e”, repetition = 2</p>
<p><strong>Output:</strong> “ecde”</p>
<p><strong>Explanation:</strong> “ecde” is the lexicographically smallest subsequence of length 4 that has the letter “e” appear at least 2 times.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> s = “bb”, k = 2, letter = “b”, repetition = 2</p>
<p><strong>Output:</strong> “bb”</p>
<p><strong>Explanation:</strong> “bb” is the only subsequence of length 2 that has the letter “b” appear at least 2 times.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= repetition <= k <= s.length <= 5 * 10<sup>4</sup></code></li>
<li><code>s</code> consists of lowercase English letters.</li>
<li><code>letter</code> is a lowercase English letter, and appears in <code>s</code> at least <code>repetition</code> times.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionsmallestSubsequence(String s, int k, char letter, int repetition)
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
smallestSubsequence
-