![]() |
VOOZH | about |
Given a string 's' and an integer k, find other string 't' such that 't' is the largest subsequence of given string 's' and each character of 't' must occur at least k times in string s.
Examples :
Input s = "geeksforgeeks" k = 2
Output geeksgeeks
Explanation 'g', 'e', 'k', and 's' appear twice or more, so the output is"geeksgeeks"
Input s = "baaabaacba" k = 3
Output baaabaaba
Explanation Characters 'b' and 'a' appear at least 3 times, so the result is"baaabaaba".
We can solve the problem by generating all subsequences of the string. For each subsequence, we check if every character appears at least k times. Among all valid subsequences, we keep track of the longest one.
geeksgeeks