Reported November 2022
ZipRecruitertwo pointers

Alternate through Forest Positions until 100

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 November 2022 looks like a story problem, but it's a pointer simulation. You start at an index, grab its value, then bounce right, left, right, left, always taking the nearest unvisited positive cell on that side. With a forest of up to 100000 cells, rescanning outward from start every turn will hurt. This is a two-pointers simulation with a skip-zeros twist. If you blank on the pointer bookkeeping during the live assessment, StealthCoder is the safety net running invisibly on your screen. But the logic is small once you see it.

The problem

Begin at start, record that index, and collect its nonnegative value. Then alternate searching right and left of start. On each side, choose the nearest not-yet-visited index with a positive value, moving farther outward on later visits to that side; zero positions are skipped.
Stop once the collected sum reaches at least 100. If the requested side has no remaining positive value, continue on the other side. If neither side has one, stop. Return visited indices.

Function
forestVisitOrder(forest: int[], start: int) → int[]

Examples
Example 1
forest = [0,0,0,20,50,0,0,30]
start = 4
return = [4,7,3]
Nearest positive right then left positions yield [4,7,3].
Example 2
forest = [100,1]
start = 0
return = [0]
The traversal stops immediately when start reaches the target.

Constraints
1 <= forest.length <= 100000
0 <= forest[i] <= 100
0 <= start < forest.length

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: visited cells on each side form a contiguous frontier, so you never need a visited set. Keep a right pointer starting at start+1 and a left pointer starting at start-1. On a right turn, advance right while forest[right] is 0, then take it and move on. Same for left going down. Each index gets passed once, so the whole thing is O(n). The common pitfall is rescanning from start every turn, which goes quadratic. Another is the fallback rule: if the requested side is exhausted, take from the other side, and if both are empty, stop. Check the sum against 100 right after the start cell and after every pick. Example 2 stops immediately at the start. Also keep the alternation turn honest when a side is skipped. If StealthCoder is your hedge in the live OA, it can sketch this pointer loop fast, but you should know the shape yourself.

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 Alternate through Forest Positions until 100 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 ZipRecruiter's OA.

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

Alternate through Forest Positions until 100 FAQ

What's the trick in this ZipRecruiter problem?+

Two pointers moving outward from start. Everything already visited on each side is contiguous, so you never track a visited set. Skip zeros as you advance each pointer, take the first positive, and check the running sum against 100. It's linear time overall.

How hard is it really?+

Easy to medium. No fancy data structure is needed. The difficulty is reading the rules carefully: alternation order, zero skipping, the fallback to the other side, and stopping the moment the sum hits 100. Most wrong answers come from edge cases, not the algorithm.

Does the start cell count toward the sum?+

Yes. You record the start index and collect its value first. Example 2 shows it: forest[0] is 100, so the sum already reaches the target and you return just [0]. Check the sum before entering the alternating loop.

What happens when one side runs out of positives?+

You continue on the other side. If the right has nothing left, keep taking from the left on every turn until the sum hits 100 or the left is also empty. When neither side has a positive value, stop and return what you've collected.

How do I prepare for this in 48 hours?+

Write the two-pointer loop from scratch once, then test it on Example 1 by hand: start 4, right gives 7, left gives 3. Also test an all-zero array, a start at an edge, and a sum that overshoots 100. That covers nearly every failure mode.

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