Count Key Changes
Reported by candidates from TikTok's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
This TikTok OA from July 2026 looks like a string problem and it's really a single pass over an array. Count Key Changes asks how many times the typed letter changes once you ignore case. If you've got an invite in your inbox, expect this to be the easy one in the set. The danger isn't difficulty, it's overthinking and burning time on a clever approach when a plain loop works. If you blank on the setup, StealthCoder runs invisibly on your screen and can hand you the loop in seconds as a safety net.
The problem
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[]) → int Examples Example 1 recording = ["w", "W", "e", "E"] return = 1 The 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 = 3 The 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 = 0 Every 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 recording is one uppercase or lowercase English letter.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is normalization. Lowercase every character, then compare each element with the one before it. If they differ, add one to the counter. That's the whole solution, O(n) time and O(1) extra space. The problem even says O(n^2) is acceptable, so nobody expects more. The common pitfalls are small. People forget to normalize case and count w to W as a change. Others compare against the first character instead of the previous one. A few miss the empty or single-element input, where the answer is 0, so start your loop at index 1. Check your code against Example 2, where C to c must not count but a to b and c to D must, giving 3. The input is an array of single-character strings, not one string, so index into the array. StealthCoder is there on the live OA if your mind goes blank, but you shouldn't need it here.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Count Key Changes cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as number of changing keys. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass TikTok's OA.
TikTok reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Count Key Changes FAQ
How hard is Count Key Changes really?+
It's easy. One loop, one comparison, one counter. The problem statement even allows O(n^2), so the bar is low. The only way to fail is a sloppy edge case or forgetting case normalization, so read the examples carefully before submitting.
What's the trick to solve it fast?+
Convert each letter to lowercase, then compare it to the previous letter. Every mismatch adds one. Start at index 1 so you never compare against nothing. You don't need a map, a stack, or any extra structure.
What edge cases should I test?+
Test a single element, which should return 0. Test all the same letter in mixed case, like Z, z, Z, which should also return 0. Test alternating letters to confirm every transition counts. Also confirm uppercase to lowercase of the same letter doesn't count.
Is this kind of problem still asked at TikTok?+
This one was reported for TikTok in July 2026, so yes, simple array and string scans still show up. Expect a warm-up problem like this alongside harder ones, and don't spend extra time polishing it.
How do I prepare in 48 hours?+
Practice quick adjacent-element comparison loops and case normalization, then spend the rest of your time on harder patterns like hash maps, sliding window, and graphs. Write this one from memory once so the syntax is automatic in your language.