You are a developer at a text processing company, and you've been tasked with a feature that identifies the longest segment of a document that contains no repeated characters. This is useful for data validation and linguistic analysis.
A "subarray" or "substring" is a contiguous sequence of characters. For example, in the string "abac", "aba" is a substring, but "aac" is not.
Given an input string s, your task is to find the length of the longest substring that contains only distinct (unique) characters.
The input consists of a single line containing the string s.
The output should be a single integer representing the length of the longest substring with all distinct characters.
If the input string is empty, the longest such substring has a length of 0.
If all characters in the string are the same, the longest such substring has a length of 1.
abacdeab
5
The input string is "abacdeab". We can examine all substrings with unique characters:
- "ab" (length 2)
- "bac" (length 3)
- "acde" (length 4)
- "bacde" (length 5)
- "cdeab" (length 5)
The maximum length among these is 5.
aaaaa
1
The only substring with distinct characters is any single character "a". The length is 1.
The expected time complexity is O(N), where N is the length of the string.
0 <= n <= 10^5, where n is the length of s.
s consists of lowercase English letters.
Time limit: 1 sec