Reported October 2022
ZipRecruiterbinary search

Number-Line Obstacles and Block Checks

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 hands you an infinite number line, and the detail that matters is the second example: a check on [-2,0] returns 1 because nothing exists yet. Negative coordinates are fair game, so no array indexed from zero. It's an ordered-set problem dressed up as a simulation. Insert obstacles, then ask whether any obstacle lands inside a window. If you blank on the data structure under pressure, StealthCoder runs invisibly during the live assessment and gives you a working approach in real time.

The problem

Process operations on an infinite integer number line:
[1, x] permanently inserts an obstacle at x.
[2, x, size] checks whether every coordinate from x through x + size - 1 is obstacle-free, without changing state.
Append 1 for a successful check and 0 otherwise. Return all check results as one binary string.

Function
processObstacleQueries(queries: int[][]) → String

Examples
Example 1
queries = [[1,2],[2,0,2],[2,0,3],[1,5],[2,3,3]]
return = "100"
[0,1] is free, [0,2] contains obstacle 2, and [3,5] contains obstacle 5.
Example 2
queries = [[2,-2,3]]
return = "1"
No obstacles exist yet.

Constraints
1 <= queries.length <= 100000
Inserted coordinates are distinct.
The total size across check queries is at most 1000000.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: a check [x, x+size-1] is free only if no obstacle sits in that range. So you need the smallest obstacle that is >= x, and you compare it to x+size-1. That's a successor query on a sorted set. In Python there's no built-in tree set, so use a sorted list with bisect (insertion cost is O(n) but memmove is fast), or process offline: collect all insert coordinates, sort them, and use a Fenwick tree or segment tree over compressed indices. The pitfall is looping over the window cell by cell. The size total is capped at 1000000, so that might pass, but don't count on it. Another pitfall is off-by-one: the range is inclusive, so the end is x+size-1. Build the output with a list and join at the end. If the structure won't come to you live, StealthCoder is the hedge.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Number-Line Obstacles and Block Checks 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 passed his OA cold and still thinks the filter is broken.

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 passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Number-Line Obstacles and Block Checks FAQ

What's the trick in this ZipRecruiter obstacle problem?+

Turn each check into a successor lookup. Find the smallest obstacle at or after x, then see whether it's greater than x+size-1. If it is, or none exists, the range is free. Everything else is bookkeeping around that one comparison.

Can I just scan every coordinate in the check range?+

The statement caps total check size at 1000000, so a brute-force scan over a hash set may technically pass. It's risky and it's not the intended solution. A sorted structure with binary search is cleaner and safer, and it's what an interviewer would expect you to explain.

How do I handle negative coordinates?+

Don't index an array by coordinate. Use a sorted list, a hash set, or coordinate compression. Example 2 checks from -2, so anything assuming non-negative values breaks immediately. Binary search over a sorted list handles negatives with no special casing.

Is the inclusive range a common bug here?+

Yes. The check covers x through x+size-1, both ends included. Writing x+size as the end will falsely reject windows when an obstacle sits right after the range. Test against Example 1: [0,1] is free even though an obstacle sits at 2.

How do I prepare for this in 48 hours?+

Practice bisect_left on a sorted list, or a TreeSet ceiling call in Java. Write the insert and successor check from memory twice. Then trace Example 1 by hand to confirm you get 100. That covers the whole pattern.

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