#C14413. Longest Unique Character Substring
Longest Unique Character Substring
Longest Unique Character Substring
You are given a string s
and your task is to find the length of the longest substring that contains no repeated characters. In other words, you have to determine the maximum length of any contiguous segment of s
in which every character is unique.
Algorithm Hint: A sliding window approach is efficient for this problem. Maintain a window with two pointers and a map (or other associative array) to track the most recent index of each character. Then, if a duplicate character is encountered, slide the left end of the window so that no duplicates remain.
Mathematical Formulation: Let \(s\) be the input string of length \(n\). We want to compute \[ L = \max_{0 \leq i \leq j < n} \{ j-i+1 \,|\, s[i:j+1] \text{ has all distinct elements} \}. \] Output \(L\) as the answer.
inputFormat
The input is read from stdin and consists of a single line that contains the string s
. The string may be empty.
outputFormat
Output to stdout a single integer representing the length of the longest substring that contains all unique characters.
## sampleabcabcbb
3