JavaScript HashMap + Binary Search. ES6, approach included with time and space. comments welcome.
\n/*\neach rectangle will have to have a number in a map {cumulative area : [Xrange, yrange]}\nfind the range of x and y per rectangle\nuse random number * leng
```\n/*\neach rectangle will have to have a number in a map {cumulative area : [Xrange, yrange]}\nfind the range of x and y per rectangle\nuse random number * length of range + low of range\n\n** need to pick randomly from sum of all areas. picking random rect and then random point inside rect won\'t do that. if one area is disproportionately bigger, it should get chosen more often.\n\nwhat if we set rect number to it\'s cumulative area -> cumulative to avoid collisions of same area rects. find random number that but <= key. in order to efficiently find the key, binary search through this.map.keys()\n*/\nclass Solution{\n    constructor(rects){\n        this.map = new Map(); //  {cumulative area : [[xLo,xHi], [yLo,yHi]]}\n        this.area = 0;\n        this.getRange(rects);\n    }\n    pick(){ \n        // O(log N) for binary search through N rectangles for random key\n        let random = Math.ceil(this.area * Math.random());\n        let randomRectKey = this.getKey(random);\n        let [xRange, yRange] = this.map.get(randomRectKey)\n        let xLength = xRange[1]-xRange[0]+1\n        let yLength = yRange[1]-yRange[0]+1\n        let xRandom = Math.floor(Math.random() * xLength) + xRange[0];\n        let yRandom = Math.floor(Math.random() * yLength) + yRange[0];\n        return [xRandom, yRandom];\n    }\n    getRange(rects){\n        // O(N) for N rectangles, construction of this.map\n        for (const rect of rects){\n            let x = rect[2] - rect[0] + 1\n            let y = rect[3] - rect[1] + 1\n            this.area += x*y\n            this.map.set(this.area, []);\n            this.map.get(this.area).push([rect[0],rect[2]]);\n            this.map.get(this.area).push([rect[1],rect[3]]);\n        }\n        // console.log(this.map)\n    }\n    getKey(num){ \n        // binary search for arr[left] just greater than num\n        // O(log N) for N rectangles\n        let arr = [...this.map.keys()];\n        let left = 0\n        let right = arr.length-1\n        while (left < right){\n            let mid = left + Math.floor((right-left)/2);\n            if (arr[mid] === num) return arr[mid];\n            if (arr[mid] < num){\n                left = mid + 1\n            } else {\n                right = mid\n            }\n        }\n        return arr[left];\n    }\n}\n```
[]