- Type: Math (random) + binary search
- Approach:
- Similar to the problem 528. Random Pick with Weight
- Init function:
- Use prefix sum to store the area of each rectangle
- Pick function:
- Find a random area from 1 to the total area
- Use binary search to search a specific area according to the random area
- Calculate the coordinates by the area
- Complexity:
- Time:
- Init:
- O(n)
- Pick:
- O(logn)
- Init:
- Space: O(n)
- Time: