Loading...
Loading...
Loading...
A scanner reads a text of letters and digits. Print the length of the longest piece of consecutive characters in which no character repeats. Checking every piece is too slow.
Example 1
Input
abcabcbb
Output
3
Example 2
Input
bbbbb
Output
1
Try the problem first. Open one hint at a time.
Checking every piece with a set is O(n²) or worse.
Slide a window. Remember the last position of each character; when a character repeats inside the window, move the left edge just past its previous position.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor