java solutions
\nclass Solution {\n    public List<Integer> fallingSquares(int[][] positions) {\n        int max = 0;\n        List<Integer> result = new ArrayList<>();\n     
```\nclass Solution {\n    public List<Integer> fallingSquares(int[][] positions) {\n        int max = 0;\n        List<Integer> result = new ArrayList<>();\n        TreeSet<Node> nodes = new TreeSet<>((n1, n2) -> n1.l - n2.l);\n        // start position 0, height 0\n        nodes.add(new Node(0, 0));\n        for (int[] position : positions) {\n            // failing square\n            Node node = new Node(position[0], position[1]);\n            // the right position\n            int r = node.l+node.h;\n            \n            // find the node before the failing square\n            Node floor = nodes.floor(node);\n            \n            // maxH is max height between node.l to r; will be add to node.h\n            int maxH = floor.h;\n            int preH = floor.h;\n            if (floor.l == node.l) {\n                floor.h = node.h;\n                node = floor;\n            } else nodes.add(node);\n            \n            Node prev = null;\n            Node curr = nodes.higher(node);\n            // iterate existing node till over the range of failing square\n            while (curr != null && curr.l < r) {\n                if (prev != null) nodes.remove(prev);\n                preH = curr.h;\n                maxH = Math.max(maxH, preH);\n                prev = curr;\n                curr = nodes.higher(curr);\n            }\n            \n            if (prev != null) prev.l = r;\n            \n            node.h += maxH;\n            nodes.add(new Node(r, preH));\n            max = Math.max(max, node.h);\n            result.add(max);\n        }\n        \n        return result;\n    }\n    \n    class Node {\n        // start position\n        int l;\n        // height\n        int h;\n        public Node(int l, int h) {\n            this.l = l;\n            this.h = h;\n        }\n    }\n}\n```
['Java', 'JavaScript']