Java Solution with Explanation
\nclass Solution {\n    Random random;\n    TreeMap<Integer,int[]> map;\n    int areaSum = 0;\n    public Solution(int[][] rects) {\n        random = new Random
```\nclass Solution {\n    Random random;\n    TreeMap<Integer,int[]> map;\n    int areaSum = 0;\n    public Solution(int[][] rects) {\n        random = new Random();\n        map = new TreeMap<>();\n        \n        for(int i = 0; i < rects.length; i++){\n            int[] rectangleCoordinates = rects[i];\n            int length = rectangleCoordinates[2] - rectangleCoordinates[0] + 1;\n            int breadth = rectangleCoordinates[3] - rectangleCoordinates[1] + 1;\n            \n            areaSum += length * breadth;\n            \n            map.put(areaSum,rectangleCoordinates);\n        }\n    }\n    \n    public int[] pick() {\n        //random.nextInt gives a int in the range of 0 to areaSum and ceilingKey returns a key greater than or equal to the argument passed\n        //to it.\n        int key = map.ceilingKey(random.nextInt(areaSum) + 1);\n        int[] rectangle = map.get(key);\n        \n        int length = rectangle[2] - rectangle[0] + 1;\n        int breadth = rectangle[3] - rectangle[1] + 1;\n        \n        //length denotes the no of x coordinates we can have.\n        //breadth denotes the no of y coordinates we can have\n        \n        //random.nextInt gives a random value from x1 - x2-1 which we can add to the current x and we can have a valid x .\n        //random.nextInt gives a random value from y1 - y2-1 which we can add to the current y and we can have a valid y .\n        \n        int x = rectangle[0] + random.nextInt(length);\n        int y = rectangle[1] + random.nextInt(breadth);\n        \n        return new int[]{x,y};\n    }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(rects);\n * int[] param_1 = obj.pick();\n */\n```
[]