#C14980. Longest Unique Substring
Longest Unique Substring
Longest Unique Substring
You are given a string S. Your task is to compute the length of the longest substring of S in which all the characters are unique. In other words, find the maximum length of a contiguous segment of S that does not contain any repeated characters.
Example:
- If S is
abcabcbb
, then the answer is3
because the longest substring with all distinct characters isabc
.
Note: The input is given as a single line from standard input, and the output should be written to standard output.
Recall that the sliding window technique is an efficient approach to solve this problem with a time complexity of \(O(n)\), where \(n\) is the length of the string.
inputFormat
Input is read from standard input. It consists of a single line containing the string S. The string can contain spaces and other printable characters.
outputFormat
Output a single integer which is the length of the longest substring that contains only unique characters.
## sampleaaaaa
1