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:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Largest substring where all characters appear at least K times | Set 2
- Largest substring with same Characters
- Find if a given string can be represented from a substring by iterating the substring “n” times
- Length of the largest substring which have character with frequency greater than or equal to half of the substring
- Longest substring with atmost K characters from the given set of characters
- Minimum number of times A has to be repeated such that B is a substring of it
- Maximum number of times str1 appears as a non-overlapping substring in str2
- Remove characters that appear more than k times
- Longest substring such that no three consecutive characters are same
- Maximum length substring having all same characters after k changes
- Count distinct substrings that contain some characters at most k times
- Remove characters from a String that appears exactly K times
- Find the String having each substring with exactly K distinct characters
- Length of the longest substring without repeating characters
- Minimum length substring with exactly K distinct characters
- Searching characters and substring in a String in Java
- Longest substring of only 4's from the first N characters of the infinite string
- Minimum characters to be replaced to remove the given substring
- Print Longest substring without repeating characters
- Largest element in the array that is repeated exactly 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.