Tap here to switch tabs
Problem
Submissions

Problem: Minimum Rectangles to Cover Points

med
30 min
Try to solve the Minimum Rectangles to Cover Points problem.

Statement

You are given a 22D integer array points where points[i] =[xi,yi]= [x_i, y_i] represents a point on the Cartesian plane, and an integer w.

You need to cover all given points using rectangles such that each rectangle has a width of at most w. A rectangle covers every point (x,y)(x, y) whose xx coordinate satisfies x1≤x≤x2x_1 \leq x \leq x_2, provided that 0≤x2−x1≤0 \leq x_2 - x_1 \leq w and the rectangle extends indefinitely along the vertical axis. Multiple points may share the same rectangle, and rectangles are allowed to overlap.

Return the minimum number of rectangles needed to cover all the points.

Note: Points are considered covered even if they lie on the boundary of a rectangle.

Constraints:

  • 1≤1 \leq points.length ≤105\leq 10^5

  • points[i].length =2= 2

  • 0≤xi=0 \leq x_i = points[i][0] ≤109\leq 10^9

  • 0≤yi=0 \leq y_i = points[i][1] ≤109\leq 10^9

  • 0≤0 \leq w ≤109\leq 10^9

  • All pairs (xi,yi)(x_i, y_i) are distinct.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Rectangles to Cover Points

med
30 min
Try to solve the Minimum Rectangles to Cover Points problem.

Statement

You are given a 22D integer array points where points[i] =[xi,yi]= [x_i, y_i] represents a point on the Cartesian plane, and an integer w.

You need to cover all given points using rectangles such that each rectangle has a width of at most w. A rectangle covers every point (x,y)(x, y) whose xx coordinate satisfies x1≤x≤x2x_1 \leq x \leq x_2, provided that 0≤x2−x1≤0 \leq x_2 - x_1 \leq w and the rectangle extends indefinitely along the vertical axis. Multiple points may share the same rectangle, and rectangles are allowed to overlap.

Return the minimum number of rectangles needed to cover all the points.

Note: Points are considered covered even if they lie on the boundary of a rectangle.

Constraints:

  • 1≤1 \leq points.length ≤105\leq 10^5

  • points[i].length =2= 2

  • 0≤xi=0 \leq x_i = points[i][0] ≤109\leq 10^9

  • 0≤yi=0 \leq y_i = points[i][1] ≤109\leq 10^9

  • 0≤0 \leq w ≤109\leq 10^9

  • All pairs (xi,yi)(x_i, y_i) are distinct.