#2014
Longest Subsequence Repeated k Times
specialist · 990 · lc hard +32 · verified · 71.3% accepted · 824 likes · top 80%
Description
Given a string s and integer k, find the longest subsequence seq such that seq repeated k times (i.e., seq * k) is itself a subsequence of s. If multiple longest answers exist, return the lexicographically largest one; return an empty string if none exists.
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.
Code
1
2
3