Given a string, find the length of the longest contiguous part of it in which no character appears twice.
Constraints
- 1 ≤ length ≤ 100000
- Printable ASCII characters without spaces
Input and output
- Input
- One line: the string s
- Output
- One integer: the maximum length.
Examples
Input 1
abcabcbbOutput
3abc
Input 2
bbbbbOutput
1b
Show hints
- Keep a window that never contains a repeat.
- When a repeat enters, where must the window start move to?
Show the explanation
Keep a window [left, right] with no repeats and remember the last index of every character. When s[right] was last seen at index p ≥ left, the window must start after it: left = p + 1. Update the last index and the best length right − left + 1 at every step.
Each index enters and leaves the window at most once, so it is O(n) time and O(alphabet) space.
Original UniCircle question. Last reviewed 21 Oct 2026.
