Reported October 2022
ZipRecruiterstring

Check a Cyclic Next-Character String

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 z-to-a wrap is where this one bites. ZipRecruiter reported this string check in October 2022, and it looks too easy to fail until you write source[i] + 1 and forget that z has no successor in ASCII. Two equal-length lowercase strings, one pass, compare each position. If you're taking this OA in the next day or two, the whole question is one line of modular arithmetic. StealthCoder sits invisibly on your screen as a safety net if you blank on the wrap and need the clean version fast.

The problem

You are given two equal-length lowercase strings, source and target.
Return true if every character in target is the next lowercase English letter after the character at the same position in source. The successor of z is a. Otherwise, return false.

Function
isNextCharacterString(source: String, target: String) → boolean

Examples
Example 1
source = "az"
target = "ba"
return = true
a advances to b, and z wraps to a.
Example 2
source = "abc"
target = "abd"
return = false
The first position fails because the successor of a is b, not a.

Constraints
1 <= source.length == target.length <= 100000
Both strings contain only lowercase English letters.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Walk both strings together. For each index i, compute the expected character as ((source[i] - 'a' + 1) % 26) + 'a' and compare it to target[i]. If any position mismatches, return false. If the loop finishes, return true. That's O(n) time and O(1) extra space, and n goes up to 100000, so don't build intermediate strings with repeated concatenation. The common pitfall is writing source[i] + 1 directly, which turns z into the character after z in ASCII and fails the "az" to "ba" example. Another slip is an off-by-one in the modulo, or comparing against the shift in the wrong direction. Return early on the first mismatch. If you freeze during the live OA, StealthCoder can hand you the modulo version while you keep typing like normal.

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 Check a Cyclic Next-Character String 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.

Check a Cyclic Next-Character String FAQ

What's the trick in the ZipRecruiter next-character string problem?+

Handle the wrap from z to a. Convert the letter to 0-25, add 1, take mod 26, then convert back. That single modulo covers every case. Without it, any source containing z fails, and the "az" to "ba" example exposes that immediately.

How hard is this problem really?+

Easy. It's a single pass over two strings with one arithmetic rule. The only way to lose is the z edge case or sloppy indexing. If you can write a loop and a modulo, you can finish it in a few minutes.

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

O(n) time, where n is the string length, and O(1) extra space. You compare character by character and return false on the first mismatch. Don't build a shifted copy of source, since that adds O(n) space for no benefit.

Which edge cases should I test before submitting?+

Test a source of just "z" with target "a", a mixed string like "az" with "ba", a failing case like "abc" with "abd", and a single-character string. Also try a case where only the last position is wrong, to confirm your loop doesn't stop early.

How do I prepare for this in 48 hours?+

Practice character arithmetic in your language: subtract 'a', apply modulo 26, add 'a' back. Write this function twice from memory and run the z wrap case. After that, review other two-string, same-index comparison problems. This one rewards habit over theory.

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