#K94522. Longest Unique Substring
Longest Unique Substring
Longest Unique Substring
You are given a string S
. Your task is to find the length of the longest contiguous substring of S
that contains only unique characters.
Problem Explanation: Given a string, determine the largest possible length of a substring in which every character appears only once. You may use the sliding window technique to achieve an efficient solution.
For example, if S = "abcabcbb"
, the longest substring with all distinct characters is "abc", which has a length of 3.
The solution should handle the case where the input string is empty, returning 0 in that case.
The mathematical formulation can be stated as: Find \[ L = \max_{0 \leq i \leq j \leq n} \{ j - i + 1 \; : \; \forall k, l \in [i, j], \text{ if } k \neq l \text{ then } S[k] \neq S[l] \} \] where n is the length of the string.
inputFormat
The input is given from stdin and consists of a single line containing the string S
.
outputFormat
Output to stdout a single integer, which is the length of the longest substring of S
that contains all unique characters.
abcabcbb
3