Reported July 2025
Metaarray

Count Key Changes

Reported by candidates from Meta's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Meta OA. Under 2s to a working solution.
Founder's read

The Meta OA reported in July 2025 hands you an array like ["W","w","a","A","a","b","B"] and asks how many times the typist switched keys. Shift and Caps Lock don't count, so 'w' then 'W' is the same key. It's a single-pass array problem dressed up as a keyboard story. You'll probably finish it fast if you stay calm and skip the clever ideas. If you blank on the case handling or an off-by-one, StealthCoder is the invisible safety net running during the live assessment. Most of the work here is reading carefully, not coding.

The problem

You are given an array of uppercase and lowercase English letters recording, representing a sequence of letters typed by a user.
Count the number of times the user changes keys while typing the sequence. Uppercase and lowercase forms of the same letter use the same letter key, so ignore modifiers such as Shift and Caps Lock. For example, typing 'w' followed by 'W' uses the same key, while typing 'W' followed by 'E' uses different keys.
A solution with time complexity no worse than O(recording.length^2) will fit within the execution time limit.

Function
solution(recording: String[]) → int

Examples
Example 1
recording = ["W","w","a","A","a","b","B"]
return = 2
After ignoring case, the sequence is w, w, a, a, a, b, b. The key changes from w to a and from a to b, for a total of 2.
Example 2
recording = ["w","w","A","w","a"]
return = 3
Ignoring case gives w, w, a, w, a. The last three boundaries change keys, so the answer is 3.

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 letter, then walk the array once and compare each element to the one before it. Every time they differ, bump a counter. That's O(n) time and O(1) extra space, far inside the stated O(n^2) allowance. The common pitfalls are small. People compare against the first element instead of the previous one. They count n instead of n-1 boundaries, or they forget to ignore case and return 0 on 'w' then 'W' pairs when they shouldn't count a change. Check Example 2: w, w, a, w, a gives changes at three boundaries, so 3. An array with one element returns 0, so start the loop at index 1. If your head goes blank mid-assessment, StealthCoder can hand you this loop in seconds while staying hidden from the proctor.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Meta's OA.

Meta reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Key Changes FAQ

How hard is the Meta Count Key Changes question really?+

It's easy. One pass, one comparison per step. The difficulty is in reading the statement correctly, especially that upper and lowercase count as the same key. If you've written a loop that compares adjacent elements before, you can finish this in a few minutes.

What's the trick to Count Key Changes?+

Lowercase each character, then compare it to the previous character. Count every mismatch. You never need a hash map, sorting, or nested loops. The whole solution is a single loop starting at index 1 with a counter.

Do I need an O(n^2) solution since the limit allows it?+

No. The O(n^2) mention is just a generous ceiling. A linear scan is simpler and faster. Don't overthink it or hunt for a harder approach. Adjacent comparison is exactly what the problem is asking for.

What edge cases should I test before submitting?+

Test a single-element array, which should return 0. Test all the same letter in mixed case, also 0. Test alternating letters like w, a, w, a, where every boundary counts. Run both given examples and confirm you get 2 and 3.

How do I prepare for this in 48 hours?+

Practice a few adjacent-element array scans and string normalization, like lowercasing before comparing. This pattern shows up in many easy OA questions. Spend the rest of your time on medium problems, since an easy one like this rarely needs more than a quick refresher.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Meta.

OA at Meta?
Invisible during screen share
Get it