Reported July 2026
TikTokbinary search

Obstacle Placement Queries

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

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

The edge case that kills the naive solution here is the block's range: x - size through x - 1, not x itself. TikTok reported this one in July 2026, and it looks easy until you scan obstacles on every query and the checks pile up. You get a stream of place-obstacle and check-block operations on an infinite number line, and you return a binary string. It's an ordered-set or sorted-structure problem in disguise. If you blank on the data structure during the live OA, StealthCoder is the safety net running invisibly on your screen.

The problem

You are given an infinite number line and an array operations. Process the operations in order while maintaining the coordinates that contain obstacles.
[1, x]: Place an obstacle at coordinate x. Coordinate x is guaranteed to contain no obstacle when this operation is performed.
[2, x, size]: Check whether a block of length size can end immediately before coordinate x. The block would occupy every integer coordinate from x - size through x - 1. Append '1' to the answer if none of those coordinates contains an obstacle; otherwise append '0'. This operation only checks feasibility and does not place the block.
Return the binary string formed by the results of all type-2 operations in their original order.

Function
obstaclePlacementQueries(operations: int[][]) → String

Examples
Example 1
operations = [[2, 0, 2], [1, 1], [2, 0, 2], [2, 2, 2]]
return = "110"
[2, 0, 2] checks coordinates -2 and -1. There are no obstacles, so append 1.
[1, 1] places an obstacle at coordinate 1.
[2, 0, 2] still checks coordinates -2 and -1. Both are free, so append 1.
[2, 2, 2] checks coordinates 0 and 1. Coordinate 1 contains an obstacle, so append 0.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The question per type-2 query is: does any obstacle lie in [x - size, x - 1]? Keep obstacles in a sorted structure, then find the largest obstacle strictly less than x. If it exists and is at least x - size, answer 0. Otherwise answer 1. That's a predecessor query, O(log n) with a balanced tree or sorted set. The pitfall is the boundary. An obstacle at exactly x doesn't block, since the block ends at x - 1. An obstacle at x - size does block. Negative coordinates are fine on an infinite line, so don't clamp at zero. Another trap is looping over every coordinate in the range, which is O(size) per query and dies on big inputs. In languages without a sorted set, you can process offline: compress coordinates and use a segment tree or Fenwick tree. If the structure escapes you mid-assessment, StealthCoder is the hedge that hands you the predecessor approach fast.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Obstacle Placement Queries 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. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as block placement queries. If you have time before the OA, drill that.

⏵ The honest play

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

TikTok reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Obstacle Placement Queries FAQ

What's the trick in Obstacle Placement Queries?+

Reduce each check to a predecessor lookup. Find the largest obstacle less than x. If it's at least x - size, the block is blocked and you append 0. Otherwise append 1. Everything else is bookkeeping with a sorted structure.

How hard is this TikTok OA question really?+

Medium. The logic is short, but you need a sorted set or an offline approach to stay fast. Brute force over the range passes small samples and fails large hidden tests. The off-by-one on the range is the other place people lose points.

Does an obstacle at x block the block?+

No. The block covers x - size through x - 1 inclusive. An obstacle at x is outside it. An obstacle at x - size is inside it. Check Example 1: the query [2, 2, 2] covers 0 and 1, and the obstacle at 1 gives 0.

What if my language has no sorted set?+

Go offline. Read all operations first, collect and compress the coordinates, then use a segment tree or Fenwick tree for max or presence queries. Or maintain a sorted list with binary search insertion if the input size allows it.

How do I prepare in 48 hours?+

Practice predecessor and successor queries on a sorted set, plus coordinate compression with a Fenwick tree. Then write this problem once from scratch and test boundaries: obstacle at x, at x - size, and negative coordinates.

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

OA at TikTok?
Invisible during screen share
Get it