Java solution with comment explanation
\n\n# Code\n\nclass Solution {\n    \n    int[][] rects;\n    TreeMap<Integer, Integer> weightedRectIndex = new TreeMap<>();\n    int nPoints = 0;\n    \n    Ra
\n\n# Code\n```\nclass Solution {\n    \n    int[][] rects;\n    TreeMap<Integer, Integer> weightedRectIndex = new TreeMap<>();\n    int nPoints = 0;\n    \n    Random rng = new Random();\n\n    public Solution(int[][] rects) {\n        this.rects = rects;\n        int index = 0;\n        for (int[] rect : rects) {\n\t\t    // inserts cumulative weight key pointing to rectangle index\n            weightedRectIndex.put(nPoints, index++);\n            nPoints += width(rect) * height(rect);\n        }\n    }\n    \n    public int[] pick() {\n\t    // generates random point within total weight\n        int point = rng.nextInt(nPoints);\n\t\t// finds appropriate rectangle\n        var entry = weightedRectIndex.floorEntry(point);\n\t\t// find point within the current rectangle\n        int rectPoint = point - entry.getKey();\n        int[] rect = rects[entry.getValue()];\n        return new int[]{\n            rect[0] + rectPoint % width(rect), \n            rect[1] + rectPoint / width(rect)};\n    }\n    \n    private int width(int[] rect) {\n        return rect[2] - rect[0] + 1;\n    }\n    \n    private int height(int[] rect) {\n        return rect[3] - rect[1] + 1;\n    }\n}\n```
['Array', 'Math', 'Binary Search', 'Reservoir Sampling', 'Java']