C++ || O(NlogN) || Binary Search
Connect with me on LinkedIn: https://www.linkedin.com/in/abhay5349singh/\n\nApproach:\n for each point, we have 2 choices: start new rectangle from it or it bec
**Connect with me on LinkedIn**: https://www.linkedin.com/in/abhay5349singh/\n\n**Approach:**\n* for each point, we have 2 choices: start new rectangle from it or it becomes part of previous rectangle\n* `net_idx` denotes nearest index to right which cannot be part of previous rectangle\n\n```\nclass Solution {\npublic:\n    \n    int search(vector<vector<int>>& points, int l, int xMax){\n        int n=points.size();\n        \n        int r = n-1;\n        while(l<r){\n            int m = l+(r-l)/2;\n            \n            if(points[m][0] > xMax){\n                r=m;\n            }else{\n                l=m+1;\n            }\n        }\n        \n        return (l<n && points[l][0]<=xMax ? l+1:l);\n    }\n    \n    int solve(vector<vector<int>>& points, int idx, int w, vector<int> &memo){\n        int n= points.size();\n        \n        if(idx == n) return 0;\n        \n        if(memo[idx] != -1) return memo[idx];\n        \n        int c = solve(points, idx+1, w, memo);\n        \n        int nxt_idx = search(points, idx+1, points[idx][0]+w);\n        c = min(c, solve(points, nxt_idx, w, memo));\n        \n        return memo[idx] = c+1;\n    }\n    \n    int minRectanglesToCoverPoints(vector<vector<int>>& points, int w) {\n        sort(points.begin(), points.end());\n        \n        int n=points.size();\n        vector<int> memo(n,-1);\n        \n        return solve(points, 0, w, memo);\n    }\n};\n```\n\n**Do upvote if it helps :)**
['Sorting', 'Binary Tree', 'C++']