Longest Substring No Repeat
Python data engineering interview problem. Difficulty: intermediate. Pattern: Sliding Window. About 14 minutes. Part of the Pro drill bank.
Length of longest substring with all unique characters. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.
A request stream may contain a long run of unique characters before a repeat appears. We want the length of the longest such contiguous part. Find the maximum length of a substring with no repeated character. A substring must use consecutive characters, and the answer is its length rather than the substring itself. Write the function length_of_longest_substring(s: str) -> int. In 'abcabcbb', the first abc has length 3 before a repeats, so the answer is 3. The starter file already has the function name and the harness print lines. Keep them, and fill only the function body.
Requirements
- Keep each candidate substring contiguous.
- Move the left boundary past a repeated character.
- Return the largest length as an integer.
Constraints
- s is a string and repeated characters may be adjacent or separated.
- An empty string has answer 0, and the return type is int.
Examples
Input: length_of_longest_substring('abcabcbb') Output: 3 abc is the longest unique window.
Topics: lakebench, python, window, unique.
More Python interview questions · All interview problems · Learn data engineering
Longest Substring No Repeat
Interview-style drill: Length of longest substring with all unique characters.
Implement `length_of_longest_substring(s: str) -> int`. Example: `"abcabcbb"` → `3` (`"abc"`). Keep the harness.