#100 · Sliding window · Intermediate · 80 XP · about 15 min
Write longest_unique(s) that returns the length of the longest substring of s in which no character appears twice. A substring is a run of characters next to each other. Upper and lower case letters are different characters, and spaces, digits and punctuation count as characters too.
longest_unique('python3pp') # returns 7 longest_unique('aaaa') # returns 1 longest_unique('swiss') # returns 3 longest_unique('') # returns 0
In 'python3pp', the run 'python3' uses seven different characters, and adding the next p would repeat one.
0 <= len(s) <= 50,000Ready?
Accept the challenge to start writing. A small timer counts the time this page is in view.
Output appears here.