Longest Stretch Without Repeats

Write the code, see it run, pass the checks.

The problem

  • medium
  • Code

Write longestUnique(text): the length of the longest stretch of text in which no character appears twice. "abcabcbb" gives 3 ("abc"), "bbbbb" gives 1 and "pwwkew" gives 3 ("wke"). Spaces and symbols count as characters. The checks include 100,000 characters, so slide a window along the text rather than checking every stretch.

Your code must pass

  • Finds the longest stretch without repeats
  • Handles empty text and one repeated letter
  • Counts spaces and symbols as characters
  • Is fast enough for 100,000 characters