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