Problem · Intervals
Obstacle Placement Queries
Learn this problemProblem statement
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 begin at coordinatex. The block would occupy every integer coordinate fromxthroughx + size - 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 = "101"[2, 0, 2]checks coordinates0and1. There are no obstacles, so append1.[1, 1]places an obstacle at coordinate1.[2, 0, 2]now intersects the obstacle at coordinate1, so append0.[2, 2, 2]checks coordinates2and3. Both are free, so append1.
More Tiktok problems
- Count Access Code PairsOA · Seen Jul 2026
- Count Key ChangesOA · Seen Jul 2026
- Travel Distance on ScootersOA · Seen Jul 2026
- Count Skipped Numbers After SubtractionsOA · Seen Jul 2026
- Repeated Grouped Digit SumOA · Seen Jul 2026
- Count Cyclic Digit PairsOA · Seen Jun 2026
- Event ID Check Completion TimesOA · Seen Jun 2026
- Check Even-Position MonotonicityOA · Seen Jun 2026