Reported September 2024
ZipRecruiterstring

Replace Every Nth 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 September 2024 looks like a string puzzle, but it really reduces to one counter and one lookup. Walk the message once, count consonants only, and every nth one gets bumped to the next consonant in bcdfghjklmnpqrstvwxyz. Case stays, z wraps to b, and everything else passes through untouched. It's an easy-to-medium problem that punishes sloppy details, not weak algorithms. If you blank on the wrap or the case handling during the live OA, StealthCoder runs invisibly on your desktop and gives you a working solution while you keep typing.

The problem

You are given a string message and a positive integer n. Scan consonant letters in message order, ignoring vowels and nonletters.
Replace every nth consonant with the next consonant in the sequence bcdfghjklmnpqrstvwxyz. Preserve case, and wrap z to b. Leave every other character unchanged.

Function
replaceEveryNthConsonant(message: String, n: int) → String

Examples
Example 1
message = "CodeSignal"
n = 3
return = "CodeTignam"
S is the third consonant and becomes T; l is the sixth consonant and becomes m.
Example 2
message = "xyz"
n = 2
return = "xzz"
y is the second consonant and advances to z.

Constraints
0 <= message.length <= 100000
1 <= n <= 100000

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that vowels and nonletters never touch your counter. Keep a running count of consonants. When count % n == 0, swap the character for its successor. Build a map from each consonant to the next one in the sequence, with z mapping to b. Then handle case: lowercase the character for the lookup, and uppercase the result if the original was uppercase. Use a char array or list and join at the end, since string concatenation in a loop is a risk with 100000 characters. The common pitfalls: counting vowels by accident, forgetting that y is a consonant here (note the sequence has y but no vowels), and replacing based on the original index instead of the consonant index. Check Example 2 by hand: xyz with n=2 gives xzz. If you freeze mid-assessment, StealthCoder is the safety net that reads the problem and hands you the code.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Replace Every Nth 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

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 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.

Replace Every Nth Consonant FAQ

How hard is the ZipRecruiter Replace Every Nth Consonant problem really?+

Easy to medium. It's a single pass with a counter and a lookup table. The difficulty is in the details: case preservation, the z to b wrap, and not counting vowels. If you've written a Caesar cipher before, you've done harder.

What's the trick to solving it fast?+

Build a map from each consonant to its successor in bcdfghjklmnpqrstvwxyz, with z going to b. Keep one counter that only increments on consonants. When the counter is divisible by n, replace the character. Everything else is copied as is.

Is y a consonant in this problem?+

Yes. The sequence bcdfghjklmnpqrstvwxyz includes y and excludes a, e, i, o, u. Example 2 confirms it: in xyz with n=2, y is the second consonant and becomes z. Treat anything in that sequence as a consonant, in either case.

How do I handle uppercase letters correctly?+

Lowercase the character to check membership and look up its successor. If the original was uppercase, uppercase the result. Example 1 shows this: S becomes T, not t. Count uppercase and lowercase consonants the same way toward the nth count.

How should I prepare for this in 48 hours?+

Write it once from scratch with a char array and a counter, then test the edge cases: empty string, n larger than the consonant count, n=1, and wrap at z. Check both examples by hand. That covers nearly every way this problem breaks.

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