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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

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
Sliding Window
Distinct Count Constraint
Frequency Counting
Divide and Conquer
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample Answer
Requirements
  • Input: string s of lowercase letters, integer k >= 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...


Submit Your Answer
Markdown supported