Random Point in Non-overlapping Rectangles

MediumArray

Description

Given non-overlapping rectangles, randomly pick an integer point inside with probability proportional to area. Return the result as an array.

Examples

Input:rects = [[-2,-2,1,1],[2,2,4,6]]
Output:[0,0]
Explanation:

Area-weighted selection.

Input:rects = [[1,1,1,1]]
Output:[1,1]
Explanation:

A rectangle with corners at (1,1) and (1,1) is a single point. The only valid integer point that can be selected is [1,1].

Input:rects = [[0,0,2,1],[3,1,5,4],[0,2,1,5]]
Output:Point in one of the rectangles
Explanation:

The selected point comes from one of the rectangles, so the output is "Point in one of the rectangles".

Constraints

  • 1 ≤ rects.length ≤ 100

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!