Imagine you're building a digital Tetris-like simulation where squares are dropped one by one onto a 2D plane! ๐ฎ
You're given a series of squares that fall from above and land on the X-axis or on top of other squares. Each square is defined by its left edge position and side length. The squares fall straight down until they hit either the ground (X-axis) or another square below them.
Key Rules:
- Squares fall one at a time in the order given
- A square stops falling when it hits the X-axis or lands on top of another square
- Squares only "land on" other squares if they overlap vertically - brushing sides doesn't count
- Once landed, squares freeze in place forever
Your Mission: After each square lands, report the maximum height of all stacked squares. Return an array where result[i] is the tallest stack height after dropping the i-th square.
Input: positions[i] = [leftEdge, sideLength] - the left coordinate and size of each square
Output: Array of maximum heights after each drop
Input & Output
Visualization
Time & Space Complexity
For each of n squares, we check overlap with all previously dropped squares
Store information for all n dropped squares
Constraints
- 1 โค positions.length โค 1000
- 1 โค lefti โค 108
- 1 โค sideLengthi โค 106
- All squares have positive side lengths
- Coordinates can be very large, requiring coordinate compression