Solving Falling Squares in go. Please try yourself first to solve the problem and submit your implementation to LeetCode before looking into solution.

Problem Description

On an infinite number line (x-axis), we drop given squares in the order they are given.

The square is dropped with the bottom edge parallel to the number line, and from a higher height than all currently landed squares. We wait for each square to stick before dropping the next.

The squares are infinitely sticky on their bottom edge, and will remain fixed to any positive length surface they touch (either the number line or another square). Squares dropped adjacent to each other will not stick together prematurely.

Example 1:

Input: [[1, 2], [2, 3], [6, 1]]
Output: [2, 5, 5]
Explanation:

Example 2:

Input: [[100, 100], [200, 100]]
Output: [100, 100]
Explanation: Adjacent squares don't get stuck prematurely - only their bottom edge can stick to surfaces.

Note:

  • 1 <= positions.length <= 1000.
  • 1 <= positions[i][0] <= 10^8.
  • 1 <= positions[i][1] <= 10^6.

_aa
_aa
-------

__aaa
__aaa
__aaa
_aa__
_aa__
--------------

__aaa
__aaa
__aaa
_aa
_aa___a
-------------- 
  • 1 <= positions.length <= 1000.
  • 1 <= positions[i][0] <= 10^8.
  • 1 <= positions[i][1] <= 10^6.

See the full details of the problem Falling Squares at LeetCode

Originally posted at: @github.com/halfrost/LeetCode-Go