FastPrepForward Block Placement Queries

Forward Block Placement Queries

Capital One logoCapital One● MediumFULLTIMEOA
Learn

Problem statement

Process operations on a nonnegative integer line. Initially, no position contains an obstacle.

  • [1, x] places an obstacle at position x. 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. Append 1 when the block fits and 0 otherwise. A query does not place a block.

Return the appended bits as one string in query order.

Function

forwardBlockPlacementQueries(operations: int[][]) → String

Examples

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.

More Capital One problems

See Capital One hiring insights
public String forwardBlockPlacementQueries(int[][] operations) {
    // Write your code here.
}
operations[[1,2],[1,5],[2,3,2],[2,3,3],[2,1,1],[2,1,2]]
expected"1010"
Checking account…