#K88637. Longest Non-Repeating Substring
Longest Non-Repeating Substring
Longest Non-Repeating Substring
Given a string s, find the length of the longest substring which does not contain any repeating characters.
More formally, you are given a string \( s \) and you need to find the maximum length \( L \) such that there exists a substring of \( s \) of length \( L \) in which every character appears at most once. This is a classic sliding window problem which can be solved in \( O(n) \) time.
For example:
- For \( s = \texttt{abcabcbb} \), the answer is 3.
- For \( s = \texttt{bbbbb} \), the answer is 1.
- For \( s = \texttt{pwwkew} \), the answer is 3.
Read the input string from standard input and output the result to standard output.
inputFormat
The input consists of a single line containing the string ( s ). The string may contain spaces and other characters.
outputFormat
Output a single integer representing the length of the longest substring without repeating characters.## sample
abcabcbb
3
</p>