FastPrepCentered Block Placement Queries

Centered Block Placement Queries

Roblox logoRoblox● MediumFULLTIMEOA
Learn

Problem statement

Process queries on an infinite integer number line while maintaining obstacle coordinates.

  • [1, x] places an obstacle at coordinate x. That coordinate is guaranteed to be empty.
  • [2, x, size] checks a centered block whose occupied integer coordinates run from x - size + 1 through x + size - 1, inclusive. Append '1' when the entire range is obstacle-free and '0' otherwise. A check does not place a block.

Return the results of all checks as one binary string.

Function

processBlockQueries(queries: int[][]) → String

Examples

Example 1

queries = [[2,0,3],[1,2],[2,0,3],[2,-3,2]]return = "101"

The first check covers -2 through 2 and is clear. After inserting at 2, the same range is blocked. The final check covers -4 through -2 and remains clear.

Example 2

queries = [[1,5],[2,5,1],[2,4,1],[2,3,3]]return = "010"

A size-one check covers only its center. The last range covers 1 through 5 and includes the obstacle.

Constraints

  • 1 <= queries.length <= 100000.
  • Insertion queries have two integers and check queries have three integers.
  • -10^9 <= x <= 10^9 and 1 <= size <= 10^9.
  • Inserted obstacle coordinates are distinct.

More Roblox problems

See Roblox hiring insights
public String processBlockQueries(int[][] queries) {
    // Write your code here.
}
queries[[2,0,3],[1,2],[2,0,3],[2,-3,2]]
expected"101"
Checking account…