An old telegraph office logs every lever an operator taps as a single letter. Each physical lever is identified by a letter of the alphabet, but the log also records whether the tap used a secondary latch, shown by the letter being uppercase instead of lowercase -- the latch state does not change which physical lever was used. So tapping t and then T counts as using the same lever twice, while tapping t and then k counts as switching levers.
Given the full tap log as a string, count how many times, moving from one tap to the very next tap, the operator used a different physical lever than immediately before (comparing letters without regard to case).
A single line containing the string s, the tap log, consisting only of uppercase and lowercase English letters.
Print a single integer: the number of consecutive tap pairs that used a different physical lever.
Example 1
Input
abAB
Expected
3
Explanation
Comparing case-insensitively: a->b differs (change), b->A differs (change, since 'b' vs 'a'), A->B differs (change, since 'a' vs 'b'). All three consecutive pairs use a different lever, so the count is 3.
Example 2
Input
AAAAaaaaBBBB
Expected
1
Explanation
The first eight characters are all the letter 'a' in some case, so there are no changes among them. The only change happens at the boundary between the last 'a' and the first 'B', giving a total count of 1.
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 →