Skip to content

Practice Number of Changing Keys

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#3019
LeetCode Problem

Number of Changing Keys

Problem Statement

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 won't be counted in 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.

Source: Number of Changing Keys on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "aAbBcC"
Output
2

# Example 2

Input
s = "AaAaAaaA"
Output
0

Constraints

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

Related LeetCode Problems

Practice more problems similar to Number of Changing Keys.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.