1
class Solution:
2
"""
3
1 <= rects.length <= 100
4
rects[i].length == 4
5
-10^9 <= ai < xi <= 10^9
6
-10^9 <= bi < yi <= 10^9
7
xi - ai <= 2000
8
yi - bi <= 2000
9
All the rectangles do not overlap.
10
At most 10^4 calls will be made to pick.
11
"""
12

13
def __init__(self, rects: List[List[int]]):
14
self.rects = rects
15
self.n_range = list(range(len(self.rects)))
16
self.weights = [(x[2] - x[0] + 1) * (x[3] - x[1] + 1) for x in rects]
17

18
def pick(self) -> List[int]:
19
rect = self.rects[choices(self.n_range, self.weights, k=1)[0]]
20
return [randint(rect[0], rect[2]), randint(rect[1], rect[3])]
21

22

23
# Your Solution object will be instantiated and called as such:
24
# obj = Solution(rects)
25
# param_1 = obj.pick()

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0