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:
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- 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
- Remove characters from a String that appears exactly K times
- Count distinct substrings that contain some characters at most k times
- Print Longest substring without repeating characters
- Minimum characters to be replaced to remove the given substring
- Length of the longest substring without repeating characters
- Searching characters and substring in a String in Java
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.