Simple C++ implementation | HashMap | Greedy | Line Sweep
Intuition\n Describe your first thoughts on how to solve this problem. \nSimple Greedy Approach.\nHeight has no constraints, so just worry about the distance co
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSimple Greedy Approach.\nHeight has no constraints, so just worry about the distance constraint in the x-axis.\n\nSimilar to Line Sweep Approach.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\ninitialize an **ORDERED** Map to store the x-values in order\nThen Simply iterate through the map, as soon as the distance between the previous and the current x-value goes beyond the given constraint, the count of rectangle increases.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n```\nO(nlogn)\n```\n\n\n# Code\n```\nclass Solution {\npublic:\n    int minRectanglesToCoverPoints(vector<vector<int>>& points, int w) {\n        \n        \n        map<int,int> mp;\n        \n        for(auto point : points) {\n            mp[point[0]]++;\n        }\n        \n        auto it = mp.begin();\n        int prev = it->first;\n        \n        int count = 0;\n        \n        for(auto it : mp) {\n            if(it.first - prev > w) {\n                count++;\n                prev = it.first;\n            }\n        }\n        \n        return count+1;\n        \n        \n    }\n};\n```
['Hash Table', 'Greedy', 'Ordered Map', 'Line Sweep', 'C++']