Turning Learners Into Developers
Codekilla
CODEKILLA
Medium
PY-004python

Longest Substring Without Repeating

Problem

Given a string, return the length of the longest substring with all distinct characters. Classic sliding-window problem.

Input
A single line string.
Output
An integer.
Constraints
0 ≤ |s| ≤ 5·10^4
Sample input
abcabcbb
Sample output
3
Explanation
The answer is `abc`, length 3.
sliding-windowstringshash-map@Google@Facebook@Amazon
Visible test cases
in: abcabcbb
out: 3
in: bbbbb
out: 1
in: pwwkew
out: 3
Your solution — run it, use AI if stuck
python