Longest Substring Where Every Character Appears at Least K Times
Company: C3 AI
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: Find the longest substring in which every present character appears at least k times. Practice divide-and-conquer splitting, frequency reasoning, and fixed-alphabet complexity.
Read the full C3 AI Data Scientist interview experience this question came from
Constraints
- 1 <= s.length <= 100000
- s contains only lowercase English letters
- 1 <= k <= 100000
Examples
Input: ('aaabb', 3)
Expected Output: 3
Explanation: The source example's substring aaa has its only character exactly three times.
Input: ('ababbc', 2)
Expected Output: 5
Explanation: The source example's substring ababb contains both a and b at least twice.
Hints
- The alphabet bounds the number of distinct characters in any window to 26.
- For each possible distinct-character count, maintain a window and track how many present characters have reached frequency k.