Reported February 2024
Navanstring

Snake-Case Iterator to Camel Case

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

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

The mistake that sinks most first attempts at this Navan OA, reported in February 2024, is treating every underscore the same. Leading and trailing ones stay. Interior runs vanish and the next letter goes uppercase. It's a string scan, not a regex puzzle, and the edge cases are where people bleed points. An all-underscore input like "___" has no letters at all, so there's no interior to speak of. If you blank on the boundary logic during the real thing, StealthCoder is the safety net running invisibly on your screen.

The problem

Convert the lowercase snake-case string produced by an iterator to camel case.
Preserve every leading and trailing underscore. Inside the remaining text, remove each nonempty run of underscores and uppercase the first following letter. If the input contains only underscores, return it unchanged.

Function
snakeIteratorToCamel(text: String) → String

Examples
Example 1
text = "__hello__world___"
return = "__helloWorld___"
Leading and trailing underscores are preserved, while the interior separator starts a new camel-case word.
Example 2
text = "___"
return = "___"
An all-underscore input is unchanged.

Constraints
1 <= text.length <= 200000.
text contains only lowercase English letters and underscores.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is to find the first and last non-underscore index, then split the string into three parts: the prefix of underscores, the core, and the suffix of underscores. If no letter exists, return the input as is. Now walk the core once. Keep a flag called capitalizeNext. When you hit an underscore, set the flag and skip. When you hit a letter, append it uppercased if the flag is set, then clear it. Collapse whole runs this way for free, because the flag doesn't stack. The common pitfall is handling runs of underscores one at a time and uppercasing twice, or trimming the edges wrong and eating the preserved ones. Also don't build the result with string concatenation in a loop, since length can reach 200000. Use a list or builder and join once. That keeps it O(n). StealthCoder is your hedge if the edge cases slip during the live OA.

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 Snake-Case Iterator 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. 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

⏵ The honest play

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

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

Snake-Case Iterator to Camel Case FAQ

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

Easy to medium. There's no fancy algorithm. It's a single linear pass with careful boundary handling. Most failures come from the leading and trailing underscore rules and the all-underscore case, not from the core conversion.

What's the trick to getting it right the first time?+

Locate the first and last letter indexes up front. Copy the underscore edges untouched. Then scan only the middle with a capitalizeNext flag. The flag handles runs of any length without special casing, so you never uppercase twice.

What edge cases should I test before submitting?+

Test "___" (all underscores), a single letter, leading underscores only, trailing underscores only, and a long interior run like "a_____b". Also test text with no underscores at all. Each one hits a different branch of the boundary logic.

Will this pass at length 200000?+

Yes, if you stay linear. One pass with a list or string builder is fine. Repeated string concatenation or slicing inside the loop can turn it quadratic in some languages, so build the output once and join at the end.

How do I prepare for this in 48 hours?+

Write the three-part split by hand twice from scratch. Then run your own tests on the edge cases above. This pattern is a string scan with a state flag, so a couple of similar string-transform drills cover what you need.

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

OA at Navan?
Invisible during screen share
Get it