#C9328. Longest Substring Without Repeating Characters

    ID: 53409 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 does not contain any repeated characters. This classic problem can be solved using the sliding window technique. Formally, if the input string is represented as \( s = s_1s_2\ldots s_n \), you need to determine the maximum \( L \) such that there exists an index \( i \) for which the substring \( s_i s_{i+1} \ldots s_{i+L-1} \) has no duplicate characters.

Example:

  • Input: abcabcbb → Output: 3
  • Input: abcdefg → Output: 7
  • Input: pwwkew → Output: 3

Your program should read the input from stdin and print the result to stdout.

inputFormat

The input consists of a single line containing a string s. The string may be empty.

outputFormat

Output a single integer denoting the length of the longest substring without repeating characters.

## sample
abcabcbb
3