Ruby Greedy with Sort: Only X-Coordinates Needed
Intuition\nWe only care about the x-coordinates for this problem. To see this, note that for any rectangle we can always just take the maximum y-coordinate.\n\n
# Intuition\nWe only care about the x-coordinates for this problem. To see this, note that for any rectangle we can always just take the maximum y-coordinate.\n\nWe sort the x-coordinates. Then we go through each x-coordinate and make a choice: 1) we can expand the current rectangle if the resulting width is less than or equal to w. Otherwise, we add a rectangle and update the starting point.\n\n# Code\n```\n# @param {Integer[][]} points\n# @param {Integer} w\n# @return {Integer}\ndef min_rectangles_to_cover_points(points, w)\n    return 1 if points.length == 1\n\n    x_cords = points.map {|p| p[0]}.sort\n    sol = 1\n    current = x_cords.shift\n\n    x_cords.each do |x|\n        next if x - current <= w\n        \n        sol += 1\n        current = x\n    end\n\n    sol\nend\n```
['Greedy', 'Ruby']