Count Key Changes
Learn this problemProblem statement
You are given an array of uppercase and lowercase English letters recording representing a sequence of letters typed by the user.
Your task is to count the number of times that the user changed keys while typing the sequence, considering that the uppercase and lowercase letters for a given letter require the user to press the same letter key (ignoring modifiers like Shift or Caps Lock). For example, typing 'w' and 'W' require the user to press the same key, whereas typing 'W' and 'E' or typing 'w' and 'e' require the user to change keys.
Note: You are not expected to provide the most optimal solution, but a solution with time complexity not worse than O(recording.length^2) will fit within the execution time limit.
Function
countKeyChanges(recording: String[]) → intExamples
Example 1
recording = ["w", "W", "e", "E"]return = 1The transition from "w" to "W" stays on the same letter key. The transition from "W" to "e" changes keys, and "e" to "E" stays on the same key. The total is 1.
Example 2
recording = ["a", "b", "C", "c", "D"]return = 3The key changes are a → b, b → C, and c → D. The pair C → c uses the same key, so the answer is 3.
Example 3
recording = ["Z", "z", "Z"]return = 0Every entry is a case variant of the letter z, so every transition uses the same key and the result is 0.
Constraints
- Every element of
recordingis one uppercase or lowercase English letter.
More Tiktok problems
- Count Access Code PairsOA · Seen Jul 2026
- Travel Distance on ScootersOA · Seen Jul 2026
- Count Skipped Numbers After SubtractionsOA · Seen Jul 2026
- Obstacle Placement QueriesOA · Seen Jul 2026
- Repeated Grouped Digit SumOA · Seen Jul 2026
- Count Cyclic Digit PairsOA · Seen Jun 2026
- Event ID Check Completion TimesOA · Seen Jun 2026
- Check Even-Position MonotonicityOA · Seen Jun 2026