Problem · Intervals
Obstacle Placement Queries
Learn this problemProblem statement
A special thank-you to the friend who kindly shared that this problem was seen again on August 4, 2026! ദ്ദി(ᵔᗜᵔ)
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 coordinatex. Coordinatexis guaranteed to contain no obstacle when this operation is performed.[2, x, size]: Check whether a block of lengthsizecan end immediately before coordinatex. The block would occupy every integer coordinate fromx - sizethroughx - 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[][]) → StringExamples
Example 1
operations = [[2, 0, 2], [1, 1], [2, 0, 2], [2, 2, 2]]return = "110"[2, 0, 2]checks coordinates-2and-1. There are no obstacles, so append1.[1, 1]places an obstacle at coordinate1.[2, 0, 2]still checks coordinates-2and-1. Both are free, so append1.[2, 2, 2]checks coordinates0and1. Coordinate1contains an obstacle, so append0.