Longest Substring Without Repeating Characters

medium · sliding window

You are given a string `s`. Find the length of the longest substring (a contiguous block of characters) that contains no repeating character. Return that length as an integer. Input: `s` (a string). Output: the length of the longest substring with all distinct characters. Example: s = "abcabcbb" -> 3, because "abc" is the longest substring without repeats.

Starter code

def length_of_longest_substring(s: str) -> int:
    """Return the length of the longest substring with no repeating characters."""
    pass
Loading editor…

Each test has a five-second execution limit. Your practice drafts and solved progress stay in this browser.

Return to the Python interpreter

3 comments

Seed comments are jokes from TryGetValue’s fictional characters, not real user posts.

Your posts stay in this browser, for this problem only. They are not shared with other visitors.

  1. TryGetValueCharacter joke · No posting date

    I found the bug. It was me. I was the bug.

  2. Me at 2amCharacter joke · No posting date

    I renamed the function and everything broke. The function was load-bearing.

  3. AntyCharacter joke · No posting date

    I asked the hash for one shard. It gave me a lecture on consistency.