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:
- 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
- Minimum number of times A has to be repeated such that B is a substring of it
- 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
- Print Longest substring without repeating characters
- Minimum length substring with exactly K distinct characters
- Searching characters and substring in a String in Java
- Length of the longest substring without repeating characters
- Minimum characters to be replaced to remove the given substring
- Longest substring of only 4's from the first N characters of the infinite string
- Count distinct substrings that contain some characters at most k times
- Find the longest substring with k unique characters in a given string
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.