ARRS-P2

The longest run of different codes

Practice 2 of 5Arrays and strings9 tests

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

  1. Hint 1Nudge
  2. Hint 2Approach Open hint 1 first
  3. Hint 3Pseudocode Open hint 2 first
  4. Worked solutionlast resort Opens after all 3 hints
Python waits for a wider screensolution.py

Ctrl + Enter runs the tests. Tab indents; press Esc, then Tab, to leave the editor.

9 tests, not run yet
Test results
#TestResultReads · time
1Repeats spread outNot run
2All the sameNot run
3EmptyNot run
4The answer is in the middleNot run
5The left end must not move backNot run
6Repeat right after the startNot run
7One codeNot run
850,000 different codesNot run
9200,000 lettersNot run