Skills101
← All coding problems

Longest Substring Without Repeating Characters

mediumSliding Window+20 XPTime limit 2s

Find the length of the longest substring (contiguous) that contains no repeated characters.

Input: one line s of lowercase letters and digits.

Output: the length of the longest substring without repeating characters.

Constraints: 1 ≤ length of s ≤ 10⁵. Use a sliding window for O(n).

Sample input 1

abcabcbb

Sample output 1

3

Sample input 2

bbbbb

Sample output 2

1

📖 Stuck? Learn the pattern

Read input from standard input and print the answer to standard output. Your code runs in a secure sandbox against the samples (Run) and hidden tests (Submit).

Loading editor…

Log in to run and submit your code — it's free.