25Longest Substring Without Repeats

    Hardsliding windowdictionaries

    Write longest_unique(text) that returns the length of the longest substring (a run of consecutive characters) that contains no repeated character.

    For "abcabcbb" the answer is 3 ("abc").

    Examples

    Example 1
    >>> longest_unique('abcabcbb')
    3
    Example 2
    >>> longest_unique('bbbbb')
    1

    Good to know

    • The last test uses a long string, so checking every substring will be too slow.

    Run examples checks the 2 examples above. Submit runs all 7 tests, including hidden edge cases, and marks the challenge solved.

    solution.py
    Loading Python…

    Test results show up here

    Write longest_unique in the editor, then run the examples. Use print() freely: its output is shown for each test.