sq to store information of squares.
sq[i] is left edge,
sq[i] is length,
sq[i] is highest point. Everytime a new square falls, check if it has overlap with previous
sq, if so, add the largest
sq[i] to its height.
class Solution(object): def fallingSquares(self, positions): """ :type positions: List[List[int]] :rtype: List[int] """ if not positions: return  sq = [[positions, positions, positions]] result = [positions] max_h = result for pos in positions[1: ]: h = pos l = pos add = 0 for prev in sq: if not l >= prev + prev and not l + h <= prev: add = max(add, prev) sq.append([l, h, h + add]) max_h = max(max_h, h + add) result.append(max_h) return result