Tap here to switch tabs
Problem
Submissions

Problem: Falling Squares

Try to solve the Falling Squares problem.

Statement

There are several square blocks dropped onto the horizontal axis in a sequence. You are given a 2D2\text{D} integer array positions where each positions[i] = [left_i, sideLength_i] represents the ithi^{th} square with a side length of sideLength_i falling such that its bottom left corner lands at the coordinate left_i.

Each block falls from an infinite height down to the ground or onto the top of previously dropped blocks. A square lands on top of another square if their horizontal intervals overlap across a non-zero length. If two squares only touch at their boundary edges, they do not stack on each other.

After dropping each block, determine the maximum height among all dropped squares.

Return an array of integers representing the maximum height observed after each respective square is dropped.

Constraints:

  • 1≤1 \leq positions.length ≤1000\leq 1000

  • 1≤1 \leq left_i ≤108\leq 10^8

  • 1≤1 \leq sideLength_i ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Falling Squares

Try to solve the Falling Squares problem.

Statement

There are several square blocks dropped onto the horizontal axis in a sequence. You are given a 2D2\text{D} integer array positions where each positions[i] = [left_i, sideLength_i] represents the ithi^{th} square with a side length of sideLength_i falling such that its bottom left corner lands at the coordinate left_i.

Each block falls from an infinite height down to the ground or onto the top of previously dropped blocks. A square lands on top of another square if their horizontal intervals overlap across a non-zero length. If two squares only touch at their boundary edges, they do not stack on each other.

After dropping each block, determine the maximum height among all dropped squares.

Return an array of integers representing the maximum height observed after each respective square is dropped.

Constraints:

  • 1≤1 \leq positions.length ≤1000\leq 1000

  • 1≤1 \leq left_i ≤108\leq 10^8

  • 1≤1 \leq sideLength_i ≤106\leq 10^6