#K67552. Smallest Substring Containing All Unique Characters
Smallest Substring Containing All Unique Characters
Smallest Substring Containing All Unique Characters
Given a string S, find the length of the smallest substring that contains every unique character present in S. In other words, if the set of unique characters in S is \( U = \{u_1, u_2, \dots, u_k\} \), determine the minimum length \( L \) such that there exists a substring of S which includes every character from \( U \).
Example:
- For
S = "abac"
, the smallest substring is "bac" and hence the answer is3
. - For
S = "aaaa"
, the unique character is just "a", so the answer is1
.
Your task is to implement a function that reads input from stdin and writes the result to stdout.
inputFormat
The input consists of a single line containing the string S (without spaces).
Input Format:
S
outputFormat
Output a single integer representing the minimum length of a substring of S that contains all unique characters present in S.
Output Format:
L## sample
abac
3