Reported September 2026
TikTokbinary search

Build Blocks from a Starting Position

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

TikTok reported this one in September 2026, and the detail that matters is the example: obstacles at 2 and 5, then a size-2 block at x=3 passes while a size-3 block at x=3 fails because it touches 5. That's the whole game. It's an obstacle-lookup problem with interleaved inserts and range checks, and the output is a binary string. If the OA lands in your inbox this week, know the data structure before you open the editor. StealthCoder sits invisibly as a safety net if you blank mid-assessment, but the idea is small enough to hold in your head.

The problem

Given an infinite number line, you would like to build few blocks and obstacles on it. Specifically, you have to implement code which supports two types of operations:
[1, x] - builds an obstacle at coordinate x along the number line. It is guaranteed that coordinate x does not contain any obstacles when the operation is performed.
[2, x, size] - checks whether it's possible to build a block of size size beginning at position x. For example, for size = 2 and x = 0, it will check 0 and 1 on the number line for obstacles. Returns 1 if it is possible, i.e. there are no obstacles at the occupied coordinates, and return 0 otherwise. Please note that this operation does not actually build the block, it only checks whether a block can be built.
Given an array of operations containing both types of operations above, your task is to return a binary string representing the outputs for all [2, x, size] operations.

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

Examples
Example 1
operations = [[1, 2], [1, 5], [2, 3, 2], [2, 3, 3], [2, 1, 1], [2, 1, 2]]
return = "1010"
For
operations = [[1, 2],
[1, 5],
[2, 3, 2],
[2, 3, 3],
[2, 1, 1],
[2, 1, 2]]
FastPrep-authored deterministic derivation: The source image is cropped before the example output. Applying the visible rules gives solution(operations) = "1010".

Constraints
FastPrep execution-adapter constraints (not shown in the source image):
Each operation is either [1, x] or [2, x, size].
Every size in a type-2 operation is positive.
Each type-1 operation targets a coordinate that does not currently contain an obstacle.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a sorted structure of obstacles. For a type-2 query covering [x, x+size-1], you need to know whether any obstacle falls in that range. Find the smallest obstacle greater than or equal to x, then check whether it's less than x+size. In Python, keep a sorted list and use bisect_left with insort for inserts. In Java, use a TreeSet and call ceiling(x). That gives O(log n) per query. The brute-force pitfall is scanning every coordinate in the block, which blows up when size is huge. Another pitfall is off-by-one: the block covers x through x+size-1, not x+size. Check your logic against the example: the size-3 block at x=3 covers 3, 4, 5 and hits the obstacle at 5. Append '1' or '0' to the output as you go, and only for type-2 operations. If you freeze on the ordered lookup, StealthCoder can feed you the bisect approach live.

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 Build Blocks from a Starting Position 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 TikTok's OA.

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

Build Blocks from a Starting Position FAQ

What's the trick in Build Blocks from a Starting Position?+

Keep obstacles in a sorted structure and, for each check, find the first obstacle at or after x. If it's less than x+size, the block is blocked and you output 0. Otherwise output 1. Never loop over every cell of the block.

How hard is this TikTok OA question really?+

Easy to medium. The logic is short, but you need an ordered lookup to be efficient. A naive scan passes the sample and may fail on large sizes. If you know bisect or TreeSet, it's a ten-minute problem.

What's the common off-by-one mistake here?+

Treating the block as covering x through x+size instead of x through x+size-1. With size 2 at x=0, it checks 0 and 1 only. Test it on the sample: size 2 at x=3 should pass with an obstacle at 5.

Do type-1 operations produce output?+

No. Only type-2 operations add a character to the result string. Type-1 operations just insert an obstacle and are guaranteed not to duplicate an existing one, so you don't need dedup logic.

How do I prepare for this in 48 hours?+

Practice binary search on a sorted list: bisect_left in Python, TreeSet ceiling in Java, or lower_bound in C++. Then write this problem once end to end and trace the sample by hand. Expect similar interval and obstacle queries.

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