Longest Prefix With No RepeatsMedium

Longest Prefix With No Repeats

MediumPractice library · +20 XPstringssliding windowhash set

Given a string S, find the length of the longest prefix of S that contains no repeating characters. If the entire string has no repeating characters, return the length of the string.

Input

A single string S (consisting of lowercase English letters).

Output

A single integer representing the length of the longest prefix of S that contains no repeating characters.

Constraints

1 <= |S| <= 200000

Time limit 1 s (native code; slower languages get more)Memory 256 MB14 hidden tests

Example 1

Input
abcabcbb
Output
3

The longest prefix with no repeating characters is 'abc', length 3.

Example 2

Input
abcdefg
Output
7

The entire string has no repeating characters, so the length is 7.

Hints