Class Solution
- java.lang.Object
-
- g2001_2100.s2030_smallest_k_length_subsequence_with_occurrences_of_a_letter.Solution
-
public class Solution extends Object
2030 - Smallest K-Length Subsequence With Occurrences of a Letter.Hard
You are given a string
s, an integerk, a letterletter, and an integerrepetition.Return the lexicographically smallest subsequence of
sof lengthkthat has the letterletterappear at leastrepetitiontimes. The test cases are generated so that theletterappears insat leastrepetitiontimes.A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.
A string
ais lexicographically smaller than a stringbif in the first position whereaandbdiffer, stringahas a letter that appears earlier in the alphabet than the corresponding letter inb.Example 1:
Input: s = “leet”, k = 3, letter = “e”, repetition = 1
Output: “eet”
Explanation: There are four subsequences of length 3 that have the letter ‘e’ appear at least 1 time:
-
“lee” (from “leet”)
-
“let” (from “leet”)
-
“let” (from “leet”)
-
“eet” (from “leet”)
The lexicographically smallest subsequence among them is “eet”.
Example 2:

Input: s = “leetcode”, k = 4, letter = “e”, repetition = 2
Output: “ecde”
Explanation: “ecde” is the lexicographically smallest subsequence of length 4 that has the letter “e” appear at least 2 times.
Example 3:
Input: s = “bb”, k = 2, letter = “b”, repetition = 2
Output: “bb”
Explanation: “bb” is the only subsequence of length 2 that has the letter “b” appear at least 2 times.
Constraints:
1 <= repetition <= k <= s.length <= 5 * 104sconsists of lowercase English letters.letteris a lowercase English letter, and appears insat leastrepetitiontimes.
-
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringsmallestSubsequence(String s, int k, char letter, int repetition)
-