Skip to content

Practice Block Placement Queries

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#3161
LeetCode Problem

Block Placement Queries

Problem Statement

Process queries on the nonnegative number line. A query [1, x] adds an obstacle at x, where none currently exists. A query [2, x, sz] asks whether a block of length sz can fit entirely within [0, x] without an obstacle in its interior; touching an obstacle is allowed. These checks do not actually place blocks or affect later queries. Return the booleans for type-2 queries in order.

Source: Block Placement Queries on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
queries = [[1,2],[2,3,3],[2,3,1],[2,2,2]]
Output
[false,true,true]

# Example 2

Input
queries = [[1,7],[2,7,6],[1,2],[2,7,5],[2,7,6]]
Output
[true,true,false]

Constraints

1 <= queries.length <= 15 * 10^4
2 <= queries[i].length <= 3
1 <= queries[i][0] <= 2
1 <= x, sz <= min(5 * 10^4, 3 * queries.length)
The input is generated such that for queries of type 1, no obstacle exists at distance x when the query is asked.
The input is generated such that there is at least one query of type 2.

Related LeetCode Problems

Practice more problems similar to Block Placement Queries.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.