Imagine you're a city planner tasked with covering specific locations with rectangular zones. You have a set of 2D points representing important locations, and you need to cover all of them using the minimum number of rectangles.
Given a 2D integer array points where points[i] = [x_i, y_i] and an integer w, your task is to cover all points with rectangles that:
- Have their lower edge at
y = 0(ground level) - Extend from
(x1, 0)to(x2, y2)wherex1 ≤ x2andy2 ≥ 0 - Have a maximum width constraint:
x2 - x1 ≤ w
A point is covered if it lies within or on the boundary of a rectangle. Points can be covered by multiple rectangles. Return the minimum number of rectangles needed to cover all points.
Example: If you have points [(0,1), (1,1), (5,1)] and w=2, you need at least 2 rectangles: one covering (0,1) and (1,1), and another covering (5,1).
Input & Output
Visualization
Time & Space Complexity
We try all possible subsets of points (2^n) and for each subset check validity (O(n))
Recursion stack depth and temporary storage for combinations
Constraints
- 1 ≤ points.length ≤ 105
- points[i].length == 2
- 0 ≤ xi, yi ≤ 109
- 0 ≤ w ≤ 109
- Note: Only x-coordinates matter for rectangle placement