Loading...
Loading...
Loading...
A scanner reads a line of characters. Print the length of the longest run of neighbouring characters in which no character appears twice.
Example 1
Input
abcabcbb
Output
3
abc has length 3.
Example 2
Input
bbbbb
Output
1
Every run is one letter.
Try the problem first. Open one hint at a time.
Keep a window of characters with no repeats, and slide its left end forward when a repeat appears.
Store the last position of each character in a dictionary to jump the left end past the earlier copy.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor