3390. Minimum Rectangles to Cover Points
My accepted Python solution to LeetCode problem 3390, Minimum Rectangles to Cover Points, running in 28ms.
- Difficulty: Medium
- Python
- Runtime 28ms
- Memory 56MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 28ms, memory 56MB, accepted 2026-01-01.
class Solution:
def minRectanglesToCoverPoints(self, points: List[List[int]], w: int) -> int:
# Sort points by x-coordinate
x_coords = sorted(set(p[0] for p in points))
count = 0
i = 0
n = len(x_coords)
while i < n:
# Start a new rectangle at x_coords[i]
start = x_coords[i]
count += 1
# Include all points with x <= start + w
while i < n and x_coords[i] <= start + w:
i += 1
return count