A building entrance logs a sequence of badge-scan IDs (single characters) as employees walk in one after another. You are given the full scan sequence as a string s. Find the length of the longest contiguous streak of scans in which no badge ID repeats.
Line 1: a non-empty string s made of uppercase letters and digits (no spaces).
A single integer: the length of the longest contiguous substring of s with all distinct characters.
s contains only uppercase letters A-Z and digits 0-9.Example 1
Input
AABCDDE
Expected
4
Explanation
The longest run of distinct badge IDs is "ABCD" (positions 2-5), length 4; "DE" after the repeat is only length 2.
Example 2
Input
Z
Expected
1
Explanation
A single scan is trivially a distinct-ID run of length 1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →