#C13372. Longest Substring Without Repeating Characters

    ID: 42903 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 without repeating characters.

You are required to compute the maximum length of a contiguous segment of characters in s such that no character appears more than once. More formally, if you denote a substring by s[i...j], then for every two indices p and q where i ≤ p, q ≤ j and p ≠ q, it must hold that s[p] \neq s[q].

The solution involves maintaining a sliding window across the string and employing a hash table (or equivalent structure) to store the last seen index of every character. The update rule ensures the window only contains unique characters, and the maximum window size encountered during the iteration is the answer.

For example, given the input abcabcbb, the longest substring without repeating characters is abc with length \(3\).

inputFormat

The input consists of a single line containing a string s.

Note: The string may include letters, digits, special characters, and can be empty.

outputFormat

Output a single integer representing the length of the longest substring of s that contains no repeating characters.

## sample
abcdefg
7