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:
- 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
- Remove characters that appear more than k times
- Maximum length substring having all same characters after k changes
- Print Longest substring without repeating characters
- Length of the longest substring without repeating characters
- Minimum length substring with exactly K distinct 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
- Searching characters and substring in a String in Java
- Count distinct substrings that contain some characters at most k times
- Find the longest substring with k unique characters in a given string
- Remove characters from string that appears strictly less than K times
- Lexicographically smallest and largest substring of size k
- 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.