Smallest substring

3.9

14 votes
Algorithms, Binary Search, Medium, Searching
Problem

You are given a string \(S\) that is made of lowercase English alphabets. Determine the length of the smallest substring that contains the maximum number of distinct characters.

Input format
The only line of input consists of a string that is made of lower case English alphabets.

Output format
Print the required answer.

Constraints
\(1 \le |S| \le 10^5\) where \(|S|\) denotes the length of the string \(S\)

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Among all substrings of length $$1$$, maximum number of distinct characters = $$1$$
Among all substrings of length $$2$$, maximum number of distinct characters = $$2$$
Among all substrings of length $$3$$, maximum number of distinct characters = $$3$$
Among all substrings of length $$4$$, maximum number of distinct characters = $$4$$
Among all substrings of length $$5$$, maximum number of distinct characters = $$4$$

Editor Image

?