Longest Substring with At Least K Repeating Characters
Medium · Hash Table, String, Divide and Conquer, Sliding Window
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.
if no such substring exists, return 0.
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.
Constraints
- 1 <= s.length <= 104
- s consists of only lowercase English letters.
- 1 <= k <= 105
Starter code (python)
class Solution(object):
def longestSubstring(self, s, k):
"""
:type s: str
:type k: int
:rtype: int
"""
Related problems
- Two Sum (Easy)
- Longest Substring Without Repeating Characters (Medium)
- Median of Two Sorted Arrays (Hard)
Previous: Perfect Rectangle · Next: Rotate Function · All problems
Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.