Sorting+ binary search||0ms beats 100%
Intuition\n Describe your first thoughts on how to solve this problem. \nConsider only the x-coordinates. Sorting them, then use binary search to find the index
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nConsider only the x-coordinates. Sorting them, then use binary search to find the index which is the beginning for the next cover\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Set array x\n2. Sort x\n3. Use while loop to proceed the binary searching (C++ upper_bound) for the beginning index for the next cover\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n\\log n)$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n# Code|| C++ 0ms beats 100%\n```\n#pragma GCC optimize("O3", "unroll-loops")\nclass Solution {\npublic:\n    int minRectanglesToCoverPoints(vector<vector<int>>& points, int w) {\n        int n=points.size();\n        vector<int> x(n,-1);\n        for(int i=0; i<n; i++) x[i]=points[i][0];\n        sort(x.begin(), x.end());\n        int ans=0, k=0;\n        while(k<n){\n            k=upper_bound(x.begin()+k, x.end(), x[k]+w)-x.begin();\n            ans++;\n        } \n        return ans; \n    }\n};\n\n\n\nauto init = []() {\n    ios::sync_with_stdio(false);\n    cin.tie(nullptr);\n    cout.tie(nullptr);\n    return \'c\';\n}();\n```
['Binary Search', 'Sorting', 'C++']