#K36162. Longest Substring Without Repeating Characters
Longest Substring Without Repeating Characters
Longest Substring Without Repeating Characters
Given a string s
, your task is to find the length of the longest substring without repeating characters. In other words, you need to compute the maximum possible value of \(\text{length} = i - j + 1\) over all indices such that the substring \(s[j \ldots i]\) contains all distinct characters.
The problem requires careful tracking of the most recent occurrence index for each character. A common approach is to use a sliding window along with a hash map (or direct indexing for ASCII) to efficiently update the start of the current window when a repeated character is encountered.
Example:
- For input "abcabcbb", the longest substring without duplicate characters is "abc" with a length of 3.
- For input "bbbbb", the longest substring is "b" with a length of 1.
- For input "pwwkew", the answer is 3 as the longest substring without repeating characters is "wke".
inputFormat
The input consists of a single line containing a string s
composed of ASCII characters.
Input is provided via stdin.
outputFormat
Output a single integer representing the length of the longest substring of s
that contains no repeated characters.
Output the result via stdout.
## sampleabcabcbb
3