#K32762. Shortest Substring with 'a', 'b', and 'c'
Shortest Substring with 'a', 'b', and 'c'
Shortest Substring with 'a', 'b', and 'c'
Given a string s consisting of lowercase English letters, your task is to find the length of the shortest contiguous substring that contains at least one occurrence of each of the characters 'a', 'b', and 'c'. If no such substring exists, output 0.
For example, if s = 'abac', the shortest substring that contains all three characters is 'bac' (or 'aba' is not valid because it misses one of the three) and its length is 3.
This problem can be efficiently solved using a sliding window technique.
inputFormat
Input is provided via standard input (stdin) as a single line containing the string s.
outputFormat
Output a single integer to standard output (stdout), representing the length of the shortest substring of s that contains at least one 'a', one 'b', and one 'c'. If there is no such substring, output 0.## sample
abac
3