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.
Input : s = "geeksforgeeks" k = 2 Output : geeksgeeks Input : s = "baaabaacba" k = 3 Output : baaabaaba
A simple solution is to generate all subsequences. For every subsequence, check if it has all characters at least k times. Find longest such subsequence. Time complexity of this approach is exponential.
Efficient Approach We can take another array to keep the record of count of each character from string s, if any character occurred more than or equal to k times, then we simply print it.
- Lexicographically largest subsequence such that every character occurs at least k times
- Longest subsequence where every character appears at-least k times
- Queries to print the character that occurs the maximum number of times in a given range
- Find number of times a string occurs as a subsequence in given string
- Longest subsequence with at least one character appearing in every string
- Number of times the given string occurs in the array in the range [l, r]
- Maximum length prefix of one string that occurs as subsequence in another
- Replace every character of string by character whose ASCII value is K times more than it
- Number of permutations of a string in which all the occurrences of a given character occurs together
- Longest Common Prefix using Character by Character Matching
- Longest subsequence such that every element in the subsequence is formed by multiplying previous element with a prime
- Count of substrings which contains a given character K times
- Number of sub-strings that contain the given character exactly k times
- Print the string after the specified character has occurred given no. of times
- Encrypt a string by repeating i-th character i times
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Sam007