Python data engineering interview problem. Difficulty: intermediate. Pattern: Sliding Window. About 14 minutes. Part of the Pro drill bank.
Longest substring with at most k distinct characters. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.
Implement length_k_distinct(s: str, k: int) -> int. ("ece").
Input: length_k_distinct('eceba', 2) Output: 3 ece uses two distinct letters.
Topics: lakebench, python, window, k-distinct.
More Python interview questions · All interview problems · Learn data engineering
Interview-style drill: Longest substring with at most k distinct characters.
Implement `length_k_distinct(s: str, k: int) -> int`. Example: `"eceba", 2` → `3` (`"ece"`). Keep the harness.