Minimum Rectangles to Cover Points Solved Medium Topics
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nApproch is explained in
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nApproch is explained in code snippet\n\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int minRectanglesToCoverPoints(int[][] A, int w) \n    {\n\n        //sorting the 2D matrix  with respect to x co ordinate using lamda expression\n        Arrays.sort(A, (a, b)->a[0] - b[0]);\n        //res is for to make a note of number of rectangles in a graoh\n        //last is used to make a note of right most edge in each bar so that it will skip all the points inside the bar \n        int res = 0, last = -1;\n        //iterating the sorted (a,b)\n        for (int[] a : A) \n        {\n            if (a[0] > last) \n            {\n                res++;//counts the number of rectangles by incrementing the res\n                last = a[0] + w;//as i said earlier last takes last edge of rectangle\n                //suppose consider x=0 &w=2 so it will add l=0+2=2 so no duplicates of first bar will be repeated. \n            }\n        }\n        return res;\n    \n    }\n}\n```
['Java']