Python3 Solution Explained | Easy to understand
Solution:\n1. First find the sum of the area of all the given rectangles\n2. Create a probability list to determine which rectangle should be selected. A rectan
**Solution:**\n1. First find the sum of the area of all the given rectangles\n2. Create a probability list to determine which rectangle should be selected. A rectangle with higher probability will be selected. The ith element of the probability list is the area of the ith rectangle devided by the sum of the area of all rectangles.\n3. Find the index of the highest probability rectangle which has the highest area by definition based on the probability list.\n4. Finaly find the 4 points of the rectangle which are x1,x2, y1,y2 and take random integer between [x1,x2]  and [y1,y2] .\n```\ndef __init__(self, rects: List[List[int]]):\n\tw = 0\n\tself.rects = rects\n\tself.probability =[]\n\tself.indexes = []\n\tfor i in range(len(self.rects)):\n\t\tself.indexes.append(i)\n\t\tw += (self.rects[i][2]-self.rects[i][0] +1)*(self.rects[i][3]-self.rects[i][1] +1)\n\tfor i in range(len(self.rects)):\n\t\tself.probability.append((self.rects[i][2]-self.rects[i][0] +1)*(self.rects[i][3]-self.rects[i][1] +1)/w)\ndef pick(self) -> List[int]:\n\tindex = random.choices(self.indexes,weights = self.probability,k=1)[-1]\n\tx1,y1,x2,y2 = self.rects[index]\n\treturn [random.randint(x1,x2),random.randint(y1,y2)]
['Prefix Sum', 'Probability and Statistics', 'Python', 'Python3']