Reported August 2026
Capital Onearray

Count Key Changes

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

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

The mistake that sinks a first attempt on this Capital One OA, reported in August 2026, is comparing raw characters and counting 'W' then 'w' as a key change. Count Key Changes looks trivial, and it is, but only if you normalize case before you compare. It's a single-pass array problem with a tiny twist. If you're taking this assessment in the next day or two, you want the pattern fast and a fallback if your brain locks up. StealthCoder runs invisibly during the live OA as a safety net if you blank, but this one's short enough that you should have it cold after reading.

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 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: char[]) → int

Examples
Example 1
recording = ["W","w","a","A","a","b","B"]
return = 2
For recording = ['W', 'w', 'a', 'A', 'a', 'b', 'B'], the output should be solution(recording) = 2.
Explanation:
Typing 'W' and 'w' require the same key 'w'.
Typing 'A' and 'a' require the same key 'a'.
Typing 'b' and 'B' require the same key 'b'.
So, the user changed keys in the following order: 'w' -> 'a' -> 'b', and the total number of key changes is 2.
Example 2
recording = ["w","w","a","w","a"]
return = 3
For recording = ['w', 'w', 'a', 'w', 'a'], the output should be solution(recording) = 3.
Explanation:
The user changed keys in the following order: 'w' -> 'a' -> 'w' -> 'a', and the total number of key changes is 3.

Constraints
Input/Output[execution time limit] 0.5 seconds (cpp)
[memory limit] 1 GB
[input] array.char recording An array of characters representing keys the user pressed. It is guaranteed that the array contains only uppercase and/or lowercase English letters. Guaranteed constraints: 1 ≤ recording.length ≤ 1000.
[output] integer The number of key changes as described above.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is to lowercase every character and compare each one to the previous character. Walk the array from index 1, and if the lowercased current differs from the lowercased previous, bump a counter. That's O(n) time and O(1) space. The problem says O(n^2) would pass, so don't overthink it. The classic pitfall is comparing raw chars, which gives 4 on Example 1 instead of 2. The second pitfall is counting distinct letters instead of adjacent changes. Example 2 shows why: w, w, a, w, a gives 3 changes, not 1. Also watch the single-element case, where the answer is 0, so don't start your loop at 0 and read index -1. If you freeze on the live OA, StealthCoder can hand you the loop, but you can write this one yourself in about two minutes.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

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. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as number of changing keys. If you have time before the OA, drill that.

⏵ The honest play

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

Capital One reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. 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 only real difficulty is remembering that uppercase and lowercase are the same key. Most candidates who fail it compare raw characters. If you normalize case first, you're done in a few lines.

What's the trick to Count Key Changes?+

Lowercase both the current and previous character before comparing. If they differ, that's a key change. You never need a hash map or a set, because only adjacent pairs matter. Shift and Caps Lock are irrelevant here.

Do I count distinct letters or adjacent changes?+

Adjacent changes. Example 2, w w a w a, returns 3 because the key switches w to a, a to w, and w to a again. Counting distinct letters would give 2 and fail. Always compare each character to the one right before it.

What edge cases should I test?+

Test a single character, which should return 0. Test all the same letter in mixed case, which should also return 0. Test strict alternation like a, B, a, B, which returns length minus 1. The two provided examples cover mixed case and repeated switching.

How do I prepare for this in 48 hours?+

Don't grind. Write this solution once from memory, then do a few other easy single-pass array and string problems so adjacent-comparison loops feel automatic. Check your language's lowercase function and confirm how it handles a char type, since that's where small syntax bugs hide.

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

OA at Capital One?
Invisible during screen share
Get it