Obstacle Placement Queries
Problem statement
You are given an infinite integer 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
solution(operations: int[][]) → StringExamples
Example 1
operations = [[1,2],[1,5],[2,5,2],[2,6,3],[2,2,1],[2,3,2]]return = "1010"- Place obstacles at coordinates
2and5. - The block before
5covers3and4, so append1. - The block before
6covers3,4, and5; coordinate5is blocked, so append0. - The block before
2covers only coordinate1, so append1. - The block before
3covers coordinates1and2; coordinate2is blocked, so append0.