Class Solution
- java.lang.Object
-
- g2001_2100.s2014_longest_subsequence_repeated_k_times.Solution
-
public class Solution extends Object
2014 - Longest Subsequence Repeated k Times.Hard
You are given a string
sof lengthn, and an integerk. You are tasked to find the longest subsequence repeatedktimes in strings.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 subsequence
seqis repeatedktimes in the stringsifseq * kis a subsequence ofs, whereseq * krepresents a string constructed by concatenatingseqktimes.- For example,
"bba"is repeated2times in the string"bababcba", because the string"bbabba", constructed by concatenating"bba"2times, is a subsequence of the string"**b**a**bab**c**ba**".
Return the longest subsequence repeated
ktimes in strings. If multiple such subsequences are found, return the lexicographically largest one. If there is no such subsequence, return an empty string.Example 1:

Input: s = “letsleetcode”, k = 2
Output: “let”
Explanation: There are two longest subsequences repeated 2 times: “let” and “ete”. “let” is the lexicographically largest one.
Example 2:
Input: s = “bb”, k = 2
Output: “b”
Explanation: The longest subsequence repeated 2 times is “b”.
Example 3:
Input: s = “ab”, k = 2
Output: ""
Explanation: There is no subsequence repeated 2 times. Empty string is returned.
Constraints:
n == s.length2 <= n, k <= 20002 <= n < k * 8sconsists of lowercase English letters.
- For example,
-
-
Constructor Summary
Constructors Constructor Description Solution()
-