Min Substring
Time: 1 s
Memory: 125 MB
Memory: 125 MB
From a given string you have to find the length of the minimum substring that contains all the unique characters that occur in it.
For example,
for string "aabbcc" the length will be 4 (we can pick the substring abbc, which contains all the unique characters of "aabbcc").
N.b: a substring is a contiguous sequence of characters within a string.The list of all substrings of the string "apple" would be "apple", "appl", "pple", "app", "ppl", "ple", "ap", "pp", "pl", "le", "a", "p", "l", "e", "".
For example,
for string "aabbcc" the length will be 4 (we can pick the substring abbc, which contains all the unique characters of "aabbcc").
N.b: a substring is a contiguous sequence of characters within a string.The list of all substrings of the string "apple" would be "apple", "appl", "pple", "app", "ppl", "ple", "ap", "pp", "pl", "le", "a", "p", "l", "e", "".
Input
you will be given a single string \(S\). Length of \(S\) will be \(1 \leq |S| \leq 10^5\)Also, \(S\) will contain only lowercase characters \((a-z)\).
Output
Print a single integer, the length of the minimum substring as discussed above.
Examples
Input | Output |
---|---|
aabbcc
|
4
|
Input | Output |
---|---|
aaaaabbb
|
2
|
Input | Output |
---|---|
aaaaa
|
1
|
Input | Output |
---|---|
aaabbbccc
|
5
|
Problem Info
Problem ID | 58 |
Time Limit | 1000 ms |
Memory Limit | 128000 KB |
Moderators | AmirHamza , sabbir_hasan_anik , uzzal_ewu |
Statistics
Submit
You need to Login or Registration for submit your solution