A planetary rover streams a diagnostic log as a string of lowercase letters, one letter recorded per tick, where each letter identifies which onboard sensor fired at that tick. Mission control calls three consecutive ticks a "clean triplet" when the three sensor codes recorded are all different from one another. Count how many clean triplets occur in the log -- equivalently, count the length-3 contiguous windows of the string whose three characters are pairwise distinct.
A single line containing the diagnostic log s.
Print a single integer: the number of clean triplets in s.
Example 1
Input
xyzzaz
Expected
1
Explanation
The length-3 windows are "xyz" (x,y,z all different -- clean), "yzz" (two z's -- not clean), "zza" (two z's -- not clean), and "zaz" (two z's -- not clean). Only one window is clean, so the answer is 1.
Example 2
Input
aababcabc
Expected
4
Explanation
The 7 windows are "aab"(dup a),"aba"(dup a),"bab"(dup b),"abc"(clean),"bca"(clean),"cab"(clean),"abc"(clean). Four windows are clean, so the answer is 4.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →