Reported September 2024
ZipRecruiterstring

Count Case-Insensitive Key Changes

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

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

The trap in this ZipRecruiter OA, reported in September 2024, is counting 'a' to 'A' as a key change. It isn't one. Same physical key, no change. Count it and you fail the hidden tests while the samples still pass. The problem is a single pass over a string with case normalization, nothing fancier. If you blank on the details during the live assessment, StealthCoder runs invisibly on your desktop and gives you the solution in real time. You probably won't need it, but it's there.

The problem

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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is to lowercase each character before you compare it to its neighbor. Loop from index 1 to the end, compare lower(s[i]) with lower(s[i-1]), and bump a counter when they differ. That's O(n) time and O(1) extra space, which is fine for 100000 characters. The common pitfall is comparing raw characters, which counts 'a' then 'A' as a change and gives the wrong answer on Example 2, where 'Zz' should return 0. Another slip is starting the loop at 0 and reading s[-1], or returning the number of distinct keys instead of the number of transitions. Normalize once up front or per comparison, either works. If the live OA rattles you and you freeze on the edge case, StealthCoder is the safety net that surfaces the clean loop while you keep typing.

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 Case-Insensitive 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

⏵ 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 ZipRecruiter's OA.

ZipRecruiter 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 Case-Insensitive Key Changes FAQ

How hard is the ZipRecruiter Count Case-Insensitive Key Changes problem really?+

Easy. It's one pass over the string with a lowercase comparison. The only way to miss is comparing raw characters and counting case flips as key changes. If you read Example 2 carefully, you'll catch it.

What's the trick to this problem?+

Normalize case before comparing adjacent characters. Lowercase both neighbors, and if they differ, add one to your count. Case differences on the same letter never count, so 'Zz' returns 0.

What's the time and space complexity I should state?+

O(n) time because you scan the string once, and O(1) extra space because you only keep a counter. With length up to 100000, that's well within what the assessment expects.

What edge cases should I test before submitting?+

A single character should return 0, since there are no transitions. An all-same-letter string with mixed case like 'aAaA' should also return 0. Alternating different letters like 'abab' should return length minus 1.

How do I prepare in 48 hours for an OA like this?+

Practice string scans with adjacent comparisons and normalization. Write this one from scratch twice, then test the edge cases by hand. Spend the rest of your time on medium problems, since an OA usually mixes difficulty levels.

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

OA at ZipRecruiter?
Invisible during screen share
Get it