bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 699. Falling Squares

699. Falling Squares

Leetcode Solutions

Brute Force with Coordinate Compression

  1. Initialize an array heights to keep track of the maximum height at each point on the X-axis after dropping the squares.
  2. Initialize an array ans to store the height of the tallest stack after each square is dropped.
  3. For each square in positions, determine the range on the X-axis that the square will cover after it is dropped.
  4. Find the maximum height within this range from the heights array. This is the height at which the current square will land.
  5. Update the heights array for the range covered by the current square by adding the side length of the square to the maximum height found in step 4.
  6. Record the new maximum height in the ans array.
  7. Return the ans array.
UML Thumbnail

Segment Tree with Lazy Propagation

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...