Skip to content

2014. Longest Subsequence Repeated k Times #1858

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to find the longest subsequence repeated k times in a given string s. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. The solution involves generating potential subsequences in descending lexicographical order and checking if they can be repeated k times within s.

Approach

  1. Frequency Analysis: First, we count the frequency of each character in the string. Only characters that appear at least k times can be part of the solution.
  2. Valid Characters: We collect characters that meet the frequency requirement and sort them in descending order to prioritize lexicographically larger …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Jun 27, 2025
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
medium Difficulty hard Difficulty
2 participants