Longest Log Substring Where Every Error Code Appears at Least K Times
Last updated: November 29, 2026
Quick Overview
Given a string of lowercase error-code letters and an integer k, return the length of the longest substring in which every letter that appears does so at least k times.
0
0
0 solved
Given a string of lowercase error-code letters and an integer k, return the length of the longest substring in which every letter that appears does so at least k times.
A Google onsite Hard problem because the natural window is not monotone: adding a character can make a bad window good. Strong candidates fix the number of distinct letters in the window, which restores monotonicity, or use divide and conquer.
What the Interviewer Expects
- Explains why a plain sliding window fails
- Fixes the number of distinct letters u from 1 to 26
- Tracks how many letters in the window reach k
- Combines results across all u
- States O(26 n) time, or gives the divide and conquer alternative
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Explain the divide and conquer approach and its worst case.
- What if the alphabet is large, like arbitrary error code strings?
- Return the substring itself.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: string
sof lowercase letters, integerk >= 1. - Output: maximum length of a substring where each present letter has frequency
>= k....
High-Level Design
With an unconstrained window, extending to the right can turn an invalid window valid (a letter reaches k), so we do not know when to shrink. Fix u, the exact number of distinct letters the window m...