Forward Block Placement Queries
Problem statement
Process operations on a nonnegative integer line. Initially, no position contains an obstacle.
[1, x]places an obstacle at positionx. Placing an obstacle at an occupied position has no additional effect.[2, start, length]asks whether every integer position in the inclusive interval[start, start + length - 1]is empty. Append1when the block fits and0otherwise. A query does not place a block.
Return the appended bits as one string in query order.
Function
forwardBlockPlacementQueries(operations: int[][]) → StringExamples
Example 1
operations = [[1,2],[1,5],[2,3,2],[2,3,3],[2,1,1],[2,1,2]]return = "1010"Positions 3 through 4 are empty, but 3 through 5 contains an obstacle. Position 1 is empty, while 1 through 2 contains an obstacle.
Example 2
operations = [[2,0,1],[1,0],[2,0,1],[1,0],[2,1,3]]return = "101"The first query succeeds. After position 0 is occupied, the second fails; repeating the build is idempotent, and positions 1 through 3 remain empty.
Constraints
1 <= operations.length <= 10^5.- Each operation is either
[1, x]or[2, start, length]. 0 <= x, start <= 10^9.1 <= length <= 10^9.- Interval endpoints fit in signed 64-bit integers.