Reported November 2022
ZipRecruiterstring

Convert Snake Case to Camel Case

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 detail that trips people on this ZipRecruiter OA, reported in November 2022, is that underscores can be leading, trailing, and consecutive. "Convert Snake Case to Camel Case" looks like a warm-up until "__a__b_" shows up in the tests. It's a string problem with one pass and no real algorithm, so the whole game is edge cases. If you've got an invite and 48 hours, this is a pattern you can lock in fast. StealthCoder sits invisibly on your screen during the live assessment as a safety net if you blank on the details.

The problem

Convert a lowercase snake-case string to lower camel case. Keep the first nonempty component lowercase, capitalize the first letter of each later nonempty component, and remove every underscore. Consecutive, leading, and trailing underscores are allowed.

Function
snakeToCamelCase(snake: String) → String

Examples
Example 1
snake = "hello_world"
return = "helloWorld"
The later component begins with an uppercase letter.
Example 2
snake = "one_two_three"
return = "oneTwoThree"
Every later component is capitalized.

Constraints
0 <= snake.length <= 100000
snake contains lowercase English letters and underscores.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a single left-to-right pass with one boolean flag, call it capitalizeNext. Start it as false and track whether you've emitted any character yet. For each character: if it's an underscore, set the flag to true and skip it. Otherwise, if the output is empty, append it as is, because the first nonempty component stays lowercase. If the output isn't empty and the flag is set, append the uppercase version and clear the flag. Else append it as is. The pitfall is leading underscores. If you set the flag on a leading underscore and don't check for an empty output, you'll capitalize the first component and fail. Use a list or StringBuilder, not repeated string concatenation, since length goes up to 100000. That's O(n) time. If you blank on the flag logic during the live OA, StealthCoder is your hedge.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Convert Snake Case to Camel Case 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 would have shipped this the night before his JPMorgan OA if he'd had it.

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 would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Convert Snake Case to Camel Case FAQ

How hard is the ZipRecruiter snake to camel case question really?+

Easy on algorithm, tricky on edge cases. There's no data structure or clever idea. The failures come from leading underscores, trailing underscores, consecutive underscores, and the empty string. Handle those four and you pass.

What's the trick to getting this right?+

Use a capitalizeNext flag and check whether the output is empty. An underscore sets the flag. A letter gets uppercased only if the flag is set and you've already emitted something. That one empty-output check handles leading underscores correctly.

What edge cases should I test before submitting?+

Test the empty string, a string of only underscores, "_a", "a_", "a__b", and "__a__b_". Expected outputs are "", "", "a", "a", "aB", and "aB". If those pass, the hidden tests almost certainly will too.

Can I just split on underscores?+

Yes, but filter out empty parts. Split on "_", drop empties, keep the first part, and capitalize the first letter of the rest. It's clean and works. The single-pass flag approach uses less memory, which matters slightly at 100000 characters.

How do I prepare for this in 48 hours?+

Write the one-pass version from scratch twice, then run the edge cases above. Also practice a few similar string transformations like reversing words or removing duplicates. This kind of question rewards careful reading of the statement more than pattern memorization.

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