#B4240. Minimum Substring Covering All Distinct Letters
Minimum Substring Covering All Distinct Letters
Minimum Substring Covering All Distinct Letters
Given a string \(S\) of length \(n\) consisting solely of uppercase and lowercase English letters, find a substring \(T\) of \(S\) such that \(T\) contains every distinct letter present in \(S\) (note that letters are case-sensitive). Output the minimum length of any such substring.
For example, if \(S = \texttt{aaBCCe}\), the distinct letters in \(S\) are \(\texttt{a}\), \(\texttt{B}\), \(\texttt{C}\) and \(\texttt{e}\). One valid minimum substring is obtained from the 2nd to the 6th character (1-indexed), i.e. \(\texttt{aBCCe}\), and thus the answer is \(5\).
inputFormat
The input consists of a single line containing the string \(S\).
outputFormat
Output an integer representing the minimum length of a substring of \(S\) that contains all distinct letters present in \(S\).
sample
aaBCCe
5