human
I found an interesting problem on https://leetcode.com/problems/longest-substring-with-at-least-k-repeating-characters/:
Find the length of the longest substring T of a given string (consists of lowercase letters only) such that every character in T appears no less than k times.

Example 1:

Input:
s = "aaabb", k = 3

Output:
3

The longest substring is "aaa", as 'a' is repeated 3 times.


Example 2:

Input:
s = "ababbc", k = 2

Output:
5

The longest substring is "ababb", as 'a' is repeated 2 times and 'b' is repeated 3 times.

I tried it in Python, but could not do it. Can you solve it?

Can you provide a Python program to find the length of the longest substring T of a given string (consists of lowercase letters only) such that every character in T appears no less than k times?
assistant
#Here is Python program to find the length of the longest substring T of a given string (consists of lowercase letters only) such that every character in T appears no less than k times.

class Solution:
     def longestSubstring(self, s, k):
         """
         :type s: str
         :type k: int
         :rtype: int
         """
         # str.count is much faster than collections.Counter under certain conditions
         # collections.Counter is intended to be a general tool
         # while str.count is much optimized C code to do just one thing 
         # (Counter in Py3 is written in C too)
         # see this SO question:
         # https://stackoverflow.com/questions/41594940/why-is-collections-counter-so-slow
         for c in set(s):
             if s.count(c) < k:
                 return max(self.longestSubstring(sub, k) for sub in s.split(c))
         return len(s)