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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Lexicographically largest subsequence such that every character occurs at least k times
- Longest subsequence where every character appears at-least k times
- Find number of times a string occurs as a subsequence in given string
- Queries to print the character that occurs the maximum number of times in a given range
- 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
- Number of permutations of a string in which all the occurrences of a given character occurs together
- Longest Subsequence with at least one common digit in every element
- Longest subsequence such that adjacent elements have at least one common digit
- Check if the string contains consecutive letters and each letter occurs exactly once
- Replace every character of string by character whose ASCII value is K times more than it
- Count substrings with each character occurring at most k times
- Length of the longest substring with every character appearing even number of times
- Longest subsequence such that every element in the subsequence is formed by multiplying previous element with a prime
- Length of longest subsequence having sum of digits of each element as a Composite Number
- Longest Common Prefix using Character by Character Matching
- Longest sub-string having frequency of each character less than equal to k
- Longest suffix such that occurrence of each character is less than N after deleting atmost K characters
- Count of numbers appearing in the given ranges at-least K 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 email@example.com. 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