Ctrl K

Key Switches While Typing

Easy
The string text is what someone typed on a keyboard, one letter at a time. A key switch happens when a letter is typed with a different key than the letter before it. Shift and Caps Lock do not matter: a and A come from the same key. Return how many times the typist switched keys.
Example 1
text="HelLo" → 3

H→e is a new key, e→l is a new key, l→L is the same key with Shift, L→o is a new key. That makes 3.

Example 2
text="mMmM" → 0

The same m key is pressed every time; case does not count.

Example 3
text="Q" → 0
Constraints
  • 1 ≤ len(text) ≤ 100
  • text consists only of lowercase and uppercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasyShared Start of Words EasyBracket Balance EasyWhere the Fragment Starts EasyLength of the Final Word Easy
loading Python…
Input
text="HelLo"
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 75 tests on the server, hidden ones included.