#K4091. Longest Substring Without Repeating Characters

    ID: 26747 Type: Default 1000ms 256MiB

Longest Substring Without Repeating Characters

Longest Substring Without Repeating Characters

Given a string S, find the length of the longest substring that contains no repeated characters. In other words, find the maximum length L such that there exists an index i where the substring \(S[i], S[i+1], \dots, S[i+L-1]\) has all unique characters.

The problem can be formulated as follows: Given a string \(S\) of length \(n\), determine the maximum \(L\) satisfying \( \forall\, j \in [i, i+L-1], \forall\, k \in [i, i+L-1] \text{ with } j \neq k,\ S[j] \neq S[k]. \)

It is recommended to use a sliding window approach for an optimal solution.

inputFormat

The input consists of a single line containing a non-empty string S (which may include spaces). The length of the string is \(n\), where \(1 \leq n \leq 10^5\).

outputFormat

Output a single integer representing the length of the longest substring of S that does not contain any repeating characters. The output should be printed to standard output.

## sample
abcabcbb
3