Java TreeMap solution only one random per pick
\nclass Solution {\n    private int[][] rects;\n    private Random r;\n    private TreeMap<Integer, Integer> map;\n    private int area;\n\n    public Solution(
```\nclass Solution {\n    private int[][] rects;\n    private Random r;\n    private TreeMap<Integer, Integer> map;\n    private int area;\n\n    public Solution(int[][] rects) {\n        this.rects = rects;\n        r = new Random();\n        map = new TreeMap<>();\n        area = 0;\n        for (int i = 0; i < rects.length; i++) {\n            area += (rects[i][2] - rects[i][0] + 1) * (rects[i][3] - rects[i][1] + 1);\n            map.put(area, i);\n        }\n    }\n    \n    public int[] pick() {\n        int randInt = r.nextInt(area);\n        int key = map.higherKey(randInt);\n        int[] rect = rects[map.get(key)];\n        int x = rect[0] + (key - randInt - 1) % (rect[2] - rect[0] + 1);\n        int y = rect[1] + (key - randInt - 1) / (rect[2] - rect[0] + 1);\n        return new int[]{x, y};\n    }\n}\n```
[]