LeetCode 395, Medium. Topics: Hash Table, String, Divide and Conquer, Sliding Window. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 20 parametrized pytest cases, and a playground notebook:
Problem
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.
Examples
Constraints
1 <= s.length <= 10^4
s consists of only lowercase English letters.
1 <= k <= 10^5
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
Last modified on September 7, 2026