[C++] Easy solution with explanation
If you are unable to solve this question, I would highly suggest you try this one first:\nhttps://leetcode.com/problems/random-pick-with-weight/\n\nIf you had s
If you are unable to solve this question, I would highly suggest you try this one first:\nhttps://leetcode.com/problems/random-pick-with-weight/\n\nIf you had solved the above question, you would understand that here the probablity of picking up a random rectangle is proportional to the number if points enclosed in the rectangle (Area). In short the number of points enclosed by the rectangle is its weight (area). \n\nNow let\'s break this problem into 2 subproblems:\n1. Pick a random rectangle based on weight (area).\n2. Pick a random point in the rectangle obtained in the first step.\n\n\n```\nclass Solution {\npublic:\n    vector<int> np;\n    vector<vector<int>> Rects;\n    Solution(vector<vector<int>>& rects) {\n        Rects = rects;\n        for(auto rect : rects){\n            int l1 = rect[2] - rect[0] + 1;\n            int l2 = rect[3] - rect[1] + 1;\n            int val = np.size() ? np.back() + (l1*l2) : l1*l2; \n            np.push_back(val);\n        }\n    }\n    \n    vector<int> pick() {\n        int m = np.back();\n        int r = rand() % m;\n        auto it = upper_bound(np.begin(), np.end(), r);\n        int rect = it - np.begin();  //end of step 1\n\t\t//step 2 begins\n        vector<int> R = Rects[rect];\n        int x = rand() % (R[2]-R[0]+1) + R[0];\n        int y = rand() % (R[3]-R[1]+1) + R[1];\n        return {x, y};\n    }\n};\n```
[]