Reported October 2022
ZipRecruiterstring

Replace Each Consonant

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 ZipRecruiter OA reported in October 2022 hands you a string problem with one oddly specific detail: the consonant alphabet is bcdfghjklmnpqrstvwxyz, so "Code Z!" turns into "Dofe B!". Not a letter shift. It's a lookup. If you've got an invite and 48 hours, this is a warm-up problem, but the case handling and the wrap from z to b are where people lose points. Input can hit 100000 characters, so keep it linear. StealthCoder sits invisibly on your screen during the live OA as a safety net if you blank on the details.

The problem

Replace every consonant letter in text with the next consonant in bcdfghjklmnpqrstvwxyz. Preserve case, wrap z to b, and leave vowels and nonletters unchanged.

Function
replaceConsonants(text: String) → String

Examples
Example 1
text = "Code Z!"
return = "Dofe B!"
C becomes D, d becomes f, and Z wraps to B; vowels and punctuation remain.
Example 2
text = "aeiou"
return = "aeiou"
Vowels are unchanged.

Constraints
0 <= text.length <= 100000

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a precomputed map. Build a dictionary from each consonant to the next one in the list bcdfghjklmnpqrstvwxyz, with z wrapping to b. Then add uppercase versions of every entry so case is preserved without extra branching. Walk the string once, replace characters found in the map, and pass everything else through untouched. Vowels, digits, spaces and punctuation all fall out naturally because they're not in the map. Join the pieces in a list or string builder, not repeated concatenation, since 100000 characters will punish quadratic string building in some languages. The common pitfalls are using c + 1 arithmetic, which turns d into e instead of f, forgetting that y is a consonant here, and mishandling Z. Empty input should return an empty string. If you freeze on the OA, StealthCoder can hand you the map-based solution in real time, but this one is easy to write cold.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Replace Each Consonant 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 by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

ZipRecruiter reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Replace Each Consonant FAQ

How hard is the ZipRecruiter Replace Each Consonant problem really?+

Easy. It's a single pass over the string with a lookup table. The difficulty is in details, not the algorithm: preserving case, wrapping z to b, and leaving vowels and nonletters alone. If you write the map carefully, it passes.

What's the trick to solving it fast?+

Build a map from each consonant to its successor in bcdfghjklmnpqrstvwxyz, with z mapping to b. Add uppercase entries too. Then loop once and replace anything found in the map. No character arithmetic needed, which avoids the vowel-skipping bugs.

Why can't I just add one to the character code?+

Because the next consonant isn't the next letter. d goes to f, h to j, n to p, t to v, and z wraps to b. Adding one lands on a vowel for several letters. You'd need skip logic, and a map is simpler and less error-prone.

What edge cases should I test?+

Test an empty string, all vowels like aeiou, uppercase Z wrapping to B, mixed case, digits and punctuation, and a long input near 100000 characters. Also confirm y maps to z and w maps to x, since y counts as a consonant in this list.

How should I prepare in 48 hours for this kind of OA?+

Practice a handful of string-mapping and single-pass problems, and get comfortable writing lookup tables fast. Focus on clean edge case handling and linear time. For this ZipRecruiter question, one quick dry run of the two examples is usually enough.

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