@@ -0,0 +1,1962 @@
+package com.freetymekiyan.algorithms.level.medium;%0A%0A/**%0A * Find the length of the longest substring T of a given string (consists of lowercase letters only) such that every%0A * character in T appears no less than k times.%0A * %3Cp%3E%0A * Example 1:%0A * %3Cp%3E%0A * Input:%0A * s = %22aaabb%22, k = 3%0A * %3Cp%3E%0A * Output:%0A * 3%0A * %3Cp%3E%0A * The longest substring is %22aaa%22, as 'a' is repeated 3 times.%0A * %3Cp%3E%0A * Example 2:%0A * %3Cp%3E%0A * Input:%0A * s = %22ababbc%22, k = 2%0A * %3Cp%3E%0A * Output:%0A * 5%0A * %3Cp%3E%0A * The longest substring is %22ababb%22, as 'a' is repeated 2 times and 'b' is repeated 3 times.%0A */%0Apublic class LongestSubstringwithAtLeastKRepeatingCharacters %7B%0A%0A    /**%0A     * Divide and conquer.%0A     * For those characters in string which repeat less than k times, we try to divide the string into two parts:%0A     * 1) left part: from the beginning to character's left%0A     * 2) right part: from the character's right to the end%0A     * The result is the larger one of these two parts.%0A     */%0A    public int longestSubstring(String s, int k) %7B%0A        return helper(s, 0, s.length(), k);%0A    %7D%0A%0A    private int helper(String s, int start, int end, int k) %7B%0A        if (end %3C start) %7B%0A            return 0;%0A        %7D%0A        if (end - start %3C k) %7B // String length less than k%0A            return 0;%0A        %7D%0A        int%5B%5D count = new int%5B26%5D; // Character count for current string%0A        for (int i = start; i %3C end; i++) %7B%0A            count%5Bs.charAt(i) - 'a'%5D++;%0A        %7D%0A        for (int i = 0; i %3C 26; i++) %7B%0A            if (count%5Bi%5D == 0) %7B%0A                continue;%0A            %7D%0A            if (count%5Bi%5D %3C k) %7B%0A                for (int j = start; j %3C end; j++) %7B%0A                    if (s.charAt(j) == i + 'a') %7B%0A                        int left = helper(s, start, j, k);%0A                        int right = helper(s, j + 1, end, k);%0A                        return Math.max(left, right);%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A        return end - start;%0A    %7D%0A%7D%0A

add Longest Substring With At Least K Repeating Chars