mediumSliding WindowPure DSA~25 min
Longest Unique Token Run
A fraud heuristic looks at a stream of single-character action codes within a session and measures the longest run during which no action repeated — a long unique run can indicate scripted, non-human behaviour. Find the length of the longest substring with all distinct characters.
Problem
Given a string s, return the length of the longest substring that contains no repeated character.
Input
A string s of length n (0 ≤ n ≤ 10^5) of printable ASCII characters.
Output
A single integer — the length of the longest substring without repeats.
Constraints
- 0 ≤ n ≤ 100,000
- Characters are arbitrary ASCII
- Substring must be contiguous
Examples
Example 1
Input
s = "abcabcbb"
Output
3
The longest run without a repeat is 'abc', length 3.
Example 2
Input
s = "bbbbb"
Output
1
Every character repeats; the best run is a single 'b'.