The problem
A signal log is a string s, one character per train. Return the length of the longest run of neighbouring characters in which no character appears twice.
longest_unique("abcabcbb") # 3: "abc"
longest_unique("pwwkew") # 3: "wke"
longest_unique("bbbbb") # 1
longest_unique("") # 0
Limits
- Up to 200,000 characters, of any kind.
Builds on ARRS-3 Sliding window and ARRS-6 Strings as arrays.
Continue on a laptop
Practice runs Python in the browser and needs a keyboard and a wider screen. Read the problem and open hints here, then write your solution on a laptop. Progress is saved per browser for now, so hints opened here stay on this device.
Need a hint?0 of 3 opened
- Hint 1Nudge
- Hint 2Approach Open hint 1 first
- Hint 3Pseudocode Open hint 2 first
- Worked solutionlast resort Opens after all 3 hints
Ctrl + Enter runs the tests. Tab indents; press Esc, then Tab, to leave the editor.
9 tests, not run yet
| # | Test | Result | Reads · time |
|---|---|---|---|
| 1 | Repeats spread out | Not run | |
| 2 | All the same | Not run | |
| 3 | Empty | Not run | |
| 4 | The answer is in the middle | Not run | |
| 5 | The left end must not move back | Not run | |
| 6 | Repeat right after the start | Not run | |
| 7 | One code | Not run | |
| 8 | 50,000 different codes | Not run | |
| 9 | 200,000 letters | Not run |