Given a string str and an integer K, the task is to find the length of the longest sub-string S’ such that every character in S’ appears at least K times.
Input: s = “xyxyyz”, k = 2
“xyxyy” is the longest sub-string where
every character appears at least twice.
Input: s = “geeksforgeeks”, k = 2
Approach: Consider all the possible sub-strings and for every sub-string, calculate the frequency of each of its character and check whether all the characters appear at least K times. For all such valid sub-strings, find the largest length possible.
Below is the implementation of the above approach:
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.
- Largest substring where all characters appear at least K times | Set 2
- Remove characters that appear more than k times
- Given an array of size n and a number k, find all elements that appear more than n/k times
- Remove elements that appear strictly less than k times
- Remove elements from the array which appear more than k times
- Count words that appear exactly two times in an array of words
- Find if a given string can be represented from a substring by iterating the substring “n” times
- Lexicographically largest subsequence such that every character occurs at least k times
- Length of the largest substring which have character with frequency greater than or equal to half of the substring
- Check if all occurrences of a character appear together
- Count of all possible Paths in a Tree such that Node X does not appear before Node Y
- Count all elements in the array which appears at least K times after their first occurrence
- Largest substring with same Characters
- Longest substring with atmost K characters from the given set of characters
- Distinct state codes that appear in a string as contiguous sub-strings
- Maximum sum possible for a sub-sequence such that no two elements appear at a distance < K in the array
- Longest subsequence where each character occurs at least k times
- Count of numbers appearing in the given ranges at-least K times
- Convert a number of length N such that it contains any one digit at least 'K' times
- Longest subsequence where every character appears 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.