9. Longest Substring Without Repeating Characters

Difficulty: medium · String, Sliding Window, Hash Table

Problem

Given a string `s`, find the length of the **longest substring** that contains no repeated character. A substring is a contiguous run of characters within the string.

Input

A single line containing `s`.

Output

Print one integer: the length of the longest such substring.

Example 1

Input:
abcabcbb
Output:
3

Explanation: The longest run without a repeated character is "abc", of length 3.

Example 2

Input:
bbbbb
Output:
1

Explanation: The longest run without a repeated character is "b", of length 1.

Example 3

Input:
pwwkew
Output:
3

Explanation: The longest run without a repeated character is "wke", of length 3.

Example 4

Input:
a
Output:
1

Explanation: The longest run without a repeated character is "a", of length 1.

Example 5

Input:
dvdf
Output:
3

Explanation: The longest run without a repeated character is "vdf", of length 3.

Example 6

Input:
abba
Output:
2

Explanation: The longest run without a repeated character is "ab", of length 2.

Example 7

Input:
tmmzuxt
Output:
5

Explanation: The longest run without a repeated character is "mzuxt", of length 5.

Example 8

Input:
au
Output:
2

Explanation: The longest run without a repeated character is "au", of length 2.

Example 9

Input:
anviaj
Output:
5

Explanation: The longest run without a repeated character is "nviaj", of length 5.

Example 10

Input:
abcdefg
Output:
7

Explanation: The longest run without a repeated character is "abcdefg", of length 7.

Constraints

- 1 <= s.length <= 5 * 10^4 - `s` consists of English letters, digits and symbols (no spaces).

Solutions are judged against 10 sample and 5 hidden tests. Sign in to solve it · All problems