heights
to keep track of the maximum height at each point on the X-axis after dropping the squares.ans
to store the height of the tallest stack after each square is dropped.positions
, determine the range on the X-axis that the square will cover after it is dropped.heights
array. This is the height at which the current square will land.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.ans
array.ans
array.