Random point in non-overlapping squares

0
Remix

Define a class for a square on the plane and return a uniformly random point inside it.

Follow-up: given many non-overlapping squares, return a point that is uniformly random over all of them, by choosing a square with probability proportional to its area (prefix sums and binary search) and then a point inside it.

UberCodingLast asked Jul 2025
No answer yet. Write the first one; the best answer gets endorsed.