Problem · Design
Build Blocks and Obstacles
Learn this problemProblem statement
Note 🐳 See source image below for the original statement :)
Imagine you’re working with an endless number line and want to place obstacles and check if you can build blocks on it. You have two types of tasks: one allows you to place an obstacle at a specific point, ensuring that spot is free when you do so. The other lets you check if it's possible to build a block of a certain size ending just before a given point, making sure there are no obstacles in the way. Your goal is to process a list of these tasks and return a string of "1"s and "0"s, where each "1" means you can build the block, and each "0" means you can't.
🧡 Shoutout for Charlotte baby 🧡
Function
buildBlocksAndObstacles(operations: int[][]) → StringExamples
Example 1
operations = [[1, 2], [1, 5], [2, 5, 2], [2, 6, 3], [2, 2, 1], [2, 3, 2]]return = "1010"Let's walk through each operation step by step:
[1, 2]: An obstacle is placed at coordinate 2.
[1, 5]: Another obstacle is placed at coordinate 5.
[2, 5, 2]: We check if we can build a block covering coordinates 3 and 4. Since there are no obstacles, the answer is "1".
[2, 6, 3]: We check if we can build a block covering coordinates 3, 4, and 5. But since there’s an obstacle at coordinate 5, the answer is "0".
[2, 2, 1]: We check if we can build a block at coordinate 1. Since there are no obstacles, the answer is "1".
[2, 3, 2]: Finally, we check if we can build a block covering coordinates 1 and 2. Since there’s an obstacle at coordinate 2, the answer is "0".
Constraints
All coordinates within operations are within the following interval [-109, 109The size from the second type of operation are positive integers which would not exceed 1091 <= operations.length <= 105A binary string representing the outputs for all [2, x, size] operationsMore Uber problems
- Last Truck to Leave the LaneOA · Seen Jul 2026
- Chain of CommandOA · Seen Jul 2026
- Jump Game with Prime-3 StepsOA · Seen Jun 2026
- Total Palindrome Substring CostOA · Seen Jun 2026
- Earliest Time All Users Are ConnectedPHONE SCREEN · Seen May 2026
- Tournament Rounds by RankPHONE SCREEN · Seen May 2026
- Farthest Seat AssignmentONSITE INTERVIEW · Seen May 2026
- Convex Function MinimizationPHONE SCREEN · Seen May 2026