JuniorString

Number of Changing Keys

You are given a 0-indexed string s typed by a user. Changing a key is defined as using a key different from the last used key. For example, s = "ab" has a change of a key while s = "bBBb" does not have any.

Return the number of times the user had to change the key.

Note: Modifiers like shift or caps lock will not be counted as changing the key. That is, if a user typed the letter 'a' and then the letter 'A', then it will not be considered as a changing of key.

Example 1
Inputs = "aAbBcC"
Output2
There are changes from A to b and from B to c, while case-only differences do not count.
Example 2
Inputs = "AaAaAaaA"
Output0
There is no change of key since only the letters 'a' and 'A' are pressed which does not require change of key.

Constraints

  • 1 <= s.length <= 100
  • s consists of only upper case and lower case English letters.

Asked at 5 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate