This "Hard" geometry problem asks if a point can move from to within a rectangle without touching or crossing any of a set of given circles. The movement is restricted to the interior of the rectangle . This problem combines pathfinding with geometric intersection checks.
Uber and Amazon ask this to test a candidate's ability to model a continuous geometric problem as a discrete graph problem. The key insight is that the destination is unreachable if the circles form a "chain" or "barrier" that connects the boundaries of the rectangle in a way that blocks the path. It tests skills in Geometry and Graph Connectivity.
The primary pattern is Union Find or BFS/DFS on a graph. You treat each circle as a node and the boundaries of the rectangle (Top, Bottom, Left, Right) as special nodes. Two circles are connected if they intersect or touch. A circle is connected to a boundary if it intersects or touches that boundary. The path from to is blocked if there is a path from the (Top or Right) boundary to the (Bottom or Left) boundary.
Imagine a rectangle .
The most common mistake is trying to use a grid-based BFS, which is inaccurate for continuous coordinates. Another error is incorrectly calculating the distance between circles (forgetting to use the squared distance to avoid floating-point issues). Many candidates also struggle with identifying which specific boundary connections actually block the path.
In geometry problems, always look for the "dual" problem. Instead of asking "Can I find a path?", ask "Is there a barrier?". Barriers are often easier to identify using connectivity algorithms like Union Find.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Detonate the Maximum Bombs | Medium | Solve | |
| Making A Large Island | Hard | Solve | |
| Detect Cycles in 2D Grid | Medium | Solve | |
| Maximum Number of Fish in a Grid | Medium | Solve | |
| Number of Enclaves | Medium | Solve |