FastPrepNumber-Line Obstacles and Block Checks

Number-Line Obstacles and Block Checks

ZipRecruiter logoZipRecruiter● EasyNEW GRADOA
Learn

Problem statement

Process operations on an infinite integer number line:

  • [1, x] permanently inserts an obstacle at x.
  • [2, x, size] checks whether every coordinate from x through x + size - 1 is obstacle-free, without changing state.

Append 1 for a successful check and 0 otherwise. Return all check results as one binary string.

Function

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

Examples

Example 1

queries = [[1,2],[2,0,2],[2,0,3],[1,5],[2,3,3]]return = "100"

[0,1] is free, [0,2] contains obstacle 2, and [3,5] contains obstacle 5.

Example 2

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

No obstacles exist yet.

Constraints

  • 1 <= queries.length <= 100000
  • Inserted coordinates are distinct.
  • The total size across check queries is at most 1000000.

More ZipRecruiter problems

See ZipRecruiter hiring insights
public String processObstacleQueries(int[][] queries) {
    // Write your code here.
}
queries[[1,2],[2,0,2],[2,0,3],[1,5],[2,3,3]]
expected"100"
Checking account…