#K33547. Smallest Substring Containing All Distinct Characters
Smallest Substring Containing All Distinct Characters
Smallest Substring Containing All Distinct Characters
Given a string \(S\) of length \(n\) and let \(k\) be the number of distinct characters in \(S\), your task is to find the length of the smallest substring of \(S\) that contains all \(k\) distinct characters. This problem requires efficient handling of substrings, and a common approach is to use the sliding window technique.
For example, consider the string "abcda". The distinct characters are {a, b, c, d} (thus \(k=4\)) and the smallest substring that contains all these characters is "bcda", which has a length of 4.
Note: The input will consist of only one string provided via standard input and the answer should be printed to standard output.
inputFormat
The input consists of a single line containing a string \(S\) composed of lowercase English letters.
Example: abcda
outputFormat
Output the length of the smallest substring of \(S\) that contains all the distinct characters present in \(S\).
Example: For the input abcda
, the output should be 4
.
abcda
4