JAVA || [Beats 100%] || Simple and Short || Custom Comparator
Sort on the basis of first index (x-axis) of each point.\nSince there is no limit on height of the rectangle, so, we can simply ignore the y-axis.\nNow, we star
Sort on the basis of first index (x-axis) of each point.\nSince there is no limit on height of the rectangle, so, we can simply ignore the y-axis.\nNow, we start putting rectangles of width `w` where ever we find the first point which is not in any rectangle.\n` if the width of a rectangle can\'t cover a point`, **we will simply put another rectangle starting from that point of `width = w` and `increase the count` of number of rectangles**.\n# Complexity\n- Time complexity: $$ O(n *logn) $$ `Because of Sorting`\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$ O(1) $$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int minRectanglesToCoverPoints(int[][] points, int w) {\n        Arrays.sort(points, new Comparator<int[]>() {\n            @Override\n            public int compare(int[] a, int[] b) {\n                return a[0] - b[0];\n            }\n        });\n\n        int ans = 0;\n        int covered = points[0][0];\n        for (int i = 0; i < points.length; i++) {\n            if (covered + w < points[i][0]) {\n                covered = points[i][0];\n                ans++;\n            }\n        }\n\n        return ans + 1;\n    }\n}\n```
['Java']