points on a plane, where points[i] = [x, y], and a number width.
Cover every point with rectangles. Each rectangle stands on the x-axis: its lower-left corner is (x1, 0) and its upper-right corner is (x2, y2), where x1 ≤ x2, y2 ≥ 0 and x2 − x1 ≤ width. The height can be anything. A point is covered if it lies inside a rectangle or on its border; rectangles may overlap.
Return the smallest number of rectangles that cover all the points.points=[[4, 7], [0, 2], [6, 1], [1, 9], [9, 3]], width=2 → 3
Three rectangles suffice: x from 0 to 2 (points at x = 0 and 1), from 4 to 6 (x = 4 and 6) and from 9 to 11 (x = 9).
points=[[5, 1], [5, 8], [5, 0]], width=0 → 1
All points lie on the line x = 5, so one rectangle of zero width is enough.
points=[[0, 0], [3, 3], [6, 6], [7, 1]], width=3 → 2
points=[[4, 7], [0, 2], [6, 1], [1, 9], [9, 3]], width=2
3
Run checks the first 3 tests in your browser. Submit checks all 120 tests on the server, hidden ones included.