FastPrepFastPrep
Problem Brief

Build Blocks and Obstacles

INTERNOA
See Uber online assessment and hiring insights

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 🧔

1Example 1

Input
operations = [[1, 2], [1, 5], [2, 5, 2], [2, 6, 3], [2, 2, 1], [2, 3, 2]]
Output
"1010"
Explanation
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

Limits and guarantees your solution can rely on.

  • All coordinates within operations are within the following interval [-109, 109
  • The size from the second type of operation are positive integers which would not exceed 109
  • 1 <= operations.length <= 105
  • A binary string representing the outputs for all [2, x, size] operations
  • public String buildBlocksAndObstacles(int[][] operations) {
      // write your code here
    }
    
    Input

    operations

    [[1, 2], [1, 5], [2, 5, 2], [2, 6, 3], [2, 2, 1], [2, 3, 2]]

    Output

    "1010"

    Sign in to submit your solution.