Description
Given non-overlapping rectangles, randomly pick an integer point inside with probability proportional to area.
Examples
Input:
rects = [[-2,-2,1,1],[2,2,4,6]]Output:
Point in one of the rectanglesExplanation:
Area-weighted selection.
Input:
rects = [[1]]Output:
Point in one of the rectanglesExplanation:
Minimal case with a single-element matrix.
Input:
rects = [[0,0,2,1],[3,1,5,4],[0,2,1,5]]Output:
Point in one of the rectanglesExplanation:
Three rectangles with areas 2, 6, and 3 respectively. The middle rectangle [3,1,5,4] has the largest area (6) so points should be selected from it most frequently, while the first rectangle [0,0,2,1] with area 2 should be selected least frequently.
Constraints
- •
1 ≤ rects.length ≤ 100