Longest Substring Without Repeating Characters

Hard 70 XPStringsSliding WindowHashing

Commonly asked at Amazon, Google, Microsoft, Adobe

Read a string and print the length of the longest substring (continuous part) that has no repeated characters.

Input
One line (may contain any characters, possibly empty).
Output
The length.
Constraints
Length up to 100,000. Aim for O(n).

Sample 1

Input

abcabcbb

Output

3

Explanation: "abc"

Sample 2

Input

pwwkew

Output

3

Explanation: "wke"

Read input with input() (no prompt message) and print only the answer. Run tries the Input box; Submit checks all test cases.

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.
The solution unlocks after 3 submissions.