Solution without binary search
\nclass Solution {\n    int[][] rects;\n    int[] range;\n    int totArea = 0;\n    Random r = new Random();\n\n    public Solution(int[][] rects) {\n        th
```\nclass Solution {\n    int[][] rects;\n    int[] range;\n    int totArea = 0;\n    Random r = new Random();\n\n    public Solution(int[][] rects) {\n        this.rects = rects;\n        range = new int[rects.length];\n        int id = 0; \n        for(int[] rect : rects){\n            int area = Math.abs((rect[2]-rect[0]+1) * (rect[3]-rect[1]+1));\n            this.totArea = this.totArea + area;\n            range[id++] = totArea;\n        }\n    }\n    \n    public int[] pick() {\n        \n        int[] res = new int[2];\n        int area = r.nextInt(totArea+1);\n        int index = 0;\n        \n        while(index < range.length && range[index] < area){\n            index++;\n        }\n        \n        int[] rect = rects[index];\n     \n        res[0] = rect[0] + (r.nextInt(rect[2]-rect[0]+1));\n        res[1] = rect[1] + (r.nextInt(rect[3]-rect[1]+1));\n\n        return res;\n        \n    }\n}\n\n\n====================Binary Search Approch========================\n\n\nclass Solution {\n    int[][] rects;\n    int[] range;\n    int totArea = 0;\n    Random r = new Random();\n\n    public Solution(int[][] rects) {\n        this.rects = rects;\n        range = new int[rects.length];\n        int id = 0; \n        for(int[] rect : rects){\n            int area = Math.abs((rect[2]-rect[0]+1) * (rect[3]-rect[1]+1));\n            this.totArea = this.totArea + area;\n            range[id++] = totArea;\n        }\n    }\n    \n    public int[] pick() {\n        \n        int[] res = new int[2];\n        int area = r.nextInt(totArea+1);\n        \n        /*\n        \n        Solution without binary search\n        \n        int index = 0;\n        while(index < range.length && range[index] < area){\n            index++;\n        }\n        \n        */\n        \n        int index = bs(area, 0, range.length-1);\n        \n        int[] rect = rects[index];\n     \n        res[0] = rect[0] + (r.nextInt(rect[2]-rect[0]+1));\n        res[1] = rect[1] + (r.nextInt(rect[3]-rect[1]+1));\n\n        return res;\n        \n    }\n    \n    public int bs(int area, int start , int end){\n        \n        int mid = 0;\n        while(start != end){\n            mid = ((end+start)/2);\n            if(area >= range[mid]){\n                 start = mid+1; \n            }else{\n               end = mid;\n            }\n        }\n        return start;\n    }\n}\n```
['Java']