#C11699. Smallest Substring with Both Characters
Smallest Substring with Both Characters
Smallest Substring with Both Characters
Given a string \(S\) consisting of lowercase letters (mainly 'a' and 'b'), find the length of the smallest contiguous substring that contains at least one 'a' and at least one 'b'. If no such substring exists, output 0.
For example, if \(S = \texttt{abba}\), one possible valid substring is "ab" which has a length of 2.
You are required to read the input from standard input (stdin) and output the result to standard output (stdout).
inputFormat
The input consists of a single line that contains a non-empty string \(S\) composed of lowercase English letters.
outputFormat
Output an integer representing the length of the smallest contiguous substring of \(S\) that contains at least one 'a' and one 'b'. If no such substring exists, output 0.
## sampleabba
2