Given a string s and an integer k, return the length of the longest substring of s such that the frequency of each character in this substring is greater than or equal to k.
class Solution {
public int longestSubstring(String s, int k) {
int res = 0;
Map<Character,Integer> map = new HashMap<>();
char[] chars = s.toCharArray();
for(char c : chars){
map.put(c,map.getOrDefault(c,0)+1);
}
for(char c:chars){
if(map.get(c) < k) {
for(String s1:s.split(String.valueOf(c))){
res = Math.max(res,longestSubstring(s1,k));
}
return res;
}
}
return s.length();
}
}