Longest Unique Run

MediumSliding Window≈ 30 min

Given a string text, return the length of the longest run of consecutive characters in which no character appears twice.

A run is a contiguous piece of the text: in "streetcar", "etcar" is a run, "stcar" is not.

Examples

text
"streetcar"  →  5     ("etcar")
"zzzz"       →  1     ("z")
"abcadefa"   →  6     ("bcadef")

Constraints

  • The text is between 0 and 50,000 characters long: letters, digits, spaces and punctuation, but no emoji (Python and TypeScript count those differently).
  • Aim for O(n): look at each character a constant number of times.
Sound off. Turn on for key clicks and a chime when the tests pass.Inline suggestions off. Recommended while you are learning. Turn on to complete words as you type.
Console
›Run to see what your code prints

Run checks the 3 visible cases here, in your browser. Submit runs all 7 on the judge, 4 of them hidden, and measures how your solution scales.