text. Return the length of its longest contiguous piece in which no character appears more than once.
The piece must be contiguous: you cannot skip characters in the middle. Spaces, digits and punctuation count as ordinary characters. For an empty string the answer is 0.text="xyzzyx" → 3
For instance xyz or zyx work, three distinct characters each. Any longer piece contains both letters z.
text="a b!a" → 4
A space counts as a character too. The piece a b! has four distinct characters; adding the final a would repeat it.
text="" → 0
An empty string has no characters, so the answer is 0.
text ≤ 5 · 10⁴text consists of English letters, digits, punctuation symbols and spacestext="xyzzyx"
3
Run checks the first 3 tests in your browser. Submit checks all 72 tests on the server, hidden ones included.