Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    699 - Falling Squares\.

    Hard

    There are several squares being dropped onto the X-axis of a 2D plane.

    You are given a 2D integer array positions where <code>positionsi = left<sub>i</sub>, sideLength<sub>i</sub></code> represents the <code>i<sup>th</sup></code> square with a side length of <code>sideLength<sub>i</sub></code> that is dropped with its left edge aligned with X-coordinate <code>left<sub>i</sub></code>.

    Each square is dropped one at a time from a height above any landed squares. It then falls downward (negative Y direction) until it either lands on the top side of another square or on the X-axis. A square brushing the left/right side of another square does not count as landing on it. Once it lands, it freezes in place and cannot be moved.

    After each square is dropped, you must record the height of the current tallest stack of squares.

    Return an integer array ans where ans[i] represents the height described above after dropping the <code>i<sup>th</sup></code> square.

    Example 1:

    Input: positions = \[\[1,2],2,3,6,1]

    Output: 2,5,5

    Explanation:

    After the first drop, the tallest stack is square 1 with a height of 2.

    After the second drop, the tallest stack is squares 1 and 2 with a height of 5.

    After the third drop, the tallest stack is still squares 1 and 2 with a height of 5.

    Thus, we return an answer of 2, 5, 5.

    Example 2:

    Input: positions = \[\[100,100],200,100]

    Output: 100,100

    Explanation:

    After the first drop, the tallest stack is square 1 with a height of 100.

    After the second drop, the tallest stack is either square 1 or square 2, both with heights of 100.

    Thus, we return an answer of 100, 100.

    Note that square 2 only brushes the right side of square 1, which does not count as landing on it.

    Constraints:

    • 1 &lt;= positions.length &lt;= 1000

    • <code>1 <= left<sub>i</sub><= 10<sup>8</sup></code>

    • <code>1 <= sideLength<sub>i</sub><= 10<sup>6</sup></code>

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final List<Integer> fallingSquares(Array<IntArray> positions)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait