Skip to main content

Medium sliding window · strings · hash map

No repeats

Type the longest run of characters you can without hitting the same key twice.

Write longestUnique(s): return the length of the longest substring (consecutive characters) of s that has no repeated character.

Use a sliding window. Call show(line) at each step with the string and the window in square brackets, for example "ab[cab]cbb", and the stage prints the window sliding.

Example: longestUnique("abcabcbb") returns 3, for "abc".

Tests you can see

  • longestUnique("abcabcbb")3
  • longestUnique("bbbbb")1
  • longestUnique("pwwkew")3

More tests are hidden. The server runs them all before a time counts.

Call show() while your code works and the run plays back here.

javascriptlongestUnique()

Tab indents · Cmd/Ctrl+Enter runs