FastPrepCount Case-Insensitive Key Changes

Count Case-Insensitive Key Changes

ZipRecruiter logoZipRecruiter● EasyNEW GRADOA
Learn

Problem statement

You are given a nonempty string recording of uppercase and lowercase English letters typed in order.

Uppercase and lowercase versions of the same letter use the same physical key. Return how many adjacent transitions change to a different key after case normalization.

Function

countKeyChanges(recording: String) → int

Examples

Example 1

recording = "aAbBc"return = 2

After normalization the sequence is a, a, b, b, c, which changes twice.

Example 2

recording = "Zz"return = 0

Both characters use the same key.

Constraints

  • 1 <= recording.length <= 100000
  • recording contains only English letters.

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int countKeyChanges(String recording) {
    // Write your code here.
}
recording"aAbBc"
expected2
Checking account…