Random Point Picker in Rectangles
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
import java.util.*;

public class Solution {
    private int[][] rects;
    private int[] areas;
    private int totalArea;
    private Random rand;

    public Solution(int[][] rects) {
        this.rects = rects;
        this.areas = new int[rects.length];
        this.totalArea = 0;
        this.rand = new Random();

        
        for (int i = 0; i < rects.length; i++) {
            int width = rects[i][2] - rects[i][0] + 1;
            int height = rects[i][3] - rects[i][1] + 1;
            areas[i] = width * height;
            totalArea += areas[i];
        }
    }

    public int[] pick() {
       
        int target = rand.nextInt(totalArea);
        int rectIndex = 0;

        while (target >= areas[rectIndex]) {
            target -= areas[rectIndex];
            rectIndex++;
        }

        
        int[] rect = rects[rectIndex];
        int x = rect[0] + rand.nextInt(rect[2] - rect[0] + 1);
        int y = rect[1] + rand.nextInt(rect[3] - rect[1] + 1);

        return new int[] {x, y};
    }
}

```
['Java']