Reported October 2022
ZipRecruiterbinary search

Advance or Jump to the Next Special Line

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 looks like a toy line-pointer problem, and that's the trap. You start at line 1, "next" adds one, and "continue" jumps to the first special line strictly greater than where you are. Sounds trivial until the inputs hit 100000 commands and a linear scan per jump quietly burns you. It's a sorted array plus binary search, dressed up as a simulation. If you blank on the jump logic, StealthCoder runs invisibly during the live assessment and hands you the approach. Read the strictly-greater part twice before you write anything.

The problem

Start at line 1. next increments the current line by one. continue jumps to the first sorted nextLine value strictly greater than the current line.
Return the final line. Every continue command is guaranteed to have a destination.

Function
navigateLines(nextLine: int[], commands: String[]) → int

Examples
Example 1
nextLine = [4,10]
commands = ["next","continue","next"]
return = 5
The path is 1 to 2 to 4 to 5.
Example 2
nextLine = [4,10]
commands = ["continue","next","next"]
return = 6
The path is 1 to 4 to 5 to 6.

Constraints
0 <= nextLine.length,commands.length <= 100000

Reported by candidates. Source: FastPrep

Pattern and pitfall

Sort nextLine once. Keep a current line value, starting at 1. For "next", add one. For "continue", binary search for the upper bound of the current line, meaning the first element strictly greater than it, and move there. That's O(n log n) for the sort and O(log n) per jump. The edge case that breaks naive solutions is strictness. If you land exactly on a special line, like line 4 in example 1, the next continue must skip past 4, not stay on it. Using lower bound instead of upper bound is the classic bug. The other pitfall is scanning from index zero on every jump, which goes quadratic at 100000 commands. You can also keep a moving pointer, but "next" can leapfrog special lines, so binary search is safer. If you freeze on the bound semantics during the live OA, StealthCoder is the safety net that shows the upper-bound version.

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 Advance or Jump to the Next Special Line 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.

Advance or Jump to the Next Special Line FAQ

What's the trick in the ZipRecruiter line navigation problem?+

Sort nextLine, then use an upper-bound binary search for every continue. The word strictly matters. If you're sitting on a special line, the jump has to go to the next larger one, not the same line. Everything else is just adding one.

How hard is this OA really?+

Easy to medium. The logic fits in about fifteen lines. The difficulty is spotting that 100000 commands means you can't scan the array each time, and getting the strictly-greater boundary right. Most failures come from off-by-one on the search.

Do I need to sort nextLine first?+

Yes. The statement says continue jumps to the first sorted nextLine value greater than the current line, so don't trust the input order. Sort a copy up front, then binary search on it. It costs O(n log n) once and keeps every jump fast.

Can I use a two-pointer instead of binary search?+

Sometimes, since the current line only increases. But next commands can skip past several special lines, so the pointer has to advance while values are less than or equal to current. It works, but binary search is simpler to get right under pressure.

How do I prepare for this in 48 hours?+

Write upper bound from scratch until it's automatic. Then trace both examples by hand, including the case where you land exactly on a special line. Test empty nextLine and empty commands too, since the constraints allow zero length for both.

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