TreeMap solution
TreeMap functions as the sorted map.\n\nclass Solution {\n    public List<Integer> fallingSquares(int[][] positions) {\n        TreeMap<Integer, Integer> map = 
TreeMap functions as the sorted map.\n```\nclass Solution {\n    public List<Integer> fallingSquares(int[][] positions) {\n        TreeMap<Integer, Integer> map = new TreeMap();\n        map.put(0, 0);\n        List<Integer> res = new ArrayList<Integer>();\n        int heighest = 0;\n        for (int i = 0; i < positions.length; i++){\n            int baseLine = 0;\n            int start = positions[i][0];\n            int end = start + positions[i][1];\n            int key = map.floorKey(start);\n            int endValue = map.get(key);\n            while (key < end){\n                endValue = map.get(key);\n                baseLine = Math.max(baseLine, map.getOrDefault(key, 0));\n                if (key >= start) map.remove(key);\n                if (map.ceilingKey(key+1) == null) break;\n                else key = map.ceilingKey(key+1);\n            }\n            int newHeight = baseLine + positions[i][1];\n            heighest = Math.max(newHeight, heighest);\n            res.add(heighest);\n            map.put(start, newHeight);\n            map.put(end, endValue);\n        }\n        return res;\n    }\n}\n```
[]