java.lang.Object
g2001_2100.s2014_longest_subsequence_repeated_k_times.Solution

public class Solution extends Object
2014 - Longest Subsequence Repeated k Times.<p>Hard</p> <p>You are given a string <code>s</code> of length <code>n</code>, and an integer <code>k</code>. You are tasked to find the <strong>longest subsequence repeated</strong> <code>k</code> times in string <code>s</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>A subsequence <code>seq</code> is <strong>repeated</strong> <code>k</code> times in the string <code>s</code> if <code>seq * k</code> is a subsequence of <code>s</code>, where <code>seq * k</code> represents a string constructed by concatenating <code>seq</code> <code>k</code> times.</p> <ul> <li>For example, <code>&quot;bba&quot;</code> is repeated <code>2</code> times in the string <code>&quot;bababcba&quot;</code>, because the string <code>&quot;bbabba&quot;</code>, constructed by concatenating <code>&quot;bba&quot;</code> <code>2</code> times, is a subsequence of the string <code>&quot;**b**a**bab**c**ba**&quot;</code>.</li> </ul> <p>Return <em>the <strong>longest subsequence repeated</strong></em> <code>k</code> <em>times in string</em> <code>s</code><em>. If multiple such subsequences are found, return the <strong>lexicographically largest</strong> one. If there is no such subsequence, return an <strong>empty</strong> string</em>.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2021/08/30/longest-subsequence-repeat-k-times.png" alt="example 1" /></p> <p><strong>Input:</strong> s = &ldquo;letsleetcode&rdquo;, k = 2</p> <p><strong>Output:</strong> &ldquo;let&rdquo;</p> <p><strong>Explanation:</strong> There are two longest subsequences repeated 2 times: &ldquo;let&rdquo; and &ldquo;ete&rdquo;. &ldquo;let&rdquo; is the lexicographically largest one.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;bb&rdquo;, k = 2</p> <p><strong>Output:</strong> &ldquo;b&rdquo;</p> <p><strong>Explanation:</strong> The longest subsequence repeated 2 times is &ldquo;b&rdquo;.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;ab&rdquo;, k = 2</p> <p><strong>Output:</strong> &quot;&quot;</p> <p><strong>Explanation:</strong> There is no subsequence repeated 2 times. Empty string is returned.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>n == s.length</code></li> <li><code>2 <= n, k <= 2000</code></li> <li><code>2 <= n < k * 8</code></li> <li><code>s</code> consists of lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • longestSubsequenceRepeatedK

      public String longestSubsequenceRepeatedK(String s, int k)