Loading...
Loading...
Loading...
A tracking code is a string. Find the length of its longest substring (a block of consecutive characters) in which no character appears twice.
Example 1
Input
abcabcbb
Output
3
The longest block without a repeat is abc, length 3.
Example 2
Input
pwwkew
Output
3
wke has length 3; pwwke is not allowed because w repeats.
Try the problem first. Open one hint at a time.
Keep a window [start, i] with no repeats, and a map from each character to the last position where it was seen.
When the current character was seen at a position >= start, move start to that position + 1.
Update the best length after every step: i - start + 1. Never move start backwards.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor