Falling Squares

Given a list of falling squares described by their left coordinate and side length, return the maximum height after each square lands. Each new square lands on the highest stack it overlaps with. This problem is a standard lazy propagation plus coordinate compression problem.

Input Format

positions = list of falling squares

Output Format

running maximum height after each square

Constraints

  • 1 <= positions.length <= 10^4
  • Each position is [left, size] and size >= 1.

Examples

Example 1:

Input:

positions = [[1,2],[2,3],[6,1]]

Output:

[2,5,5]

Explanation:

The first square has height 2. The second overlaps the first and stacks to height 5. The third does not overlap and leaves the maximum height at 5.

Example 2:

Input:

positions = [[100,100],[200,100]]

Output:

[100,100]

Explanation:

The squares do not overlap, so the maximum height remains 100 after each drop.

Loading...
Falling Squares - Advanced Trees DSA Problem