The Erect the Fence II coding problem is a variation of the Convex Hull problem, but instead of finding a polygon, you are often asked to find the Smallest Enclosing Circle. You are given a set of points and need to find the center and radius of the smallest circle that contains all the points.
Google uses this Hard difficulty geometry problem to test advanced algorithmic knowledge. Unlike the standard fence problem, this requires a randomized algorithm or a recursive approach (Welzl's Algorithm). it evaluates whether a candidate can handle complex geometric constraints and implement an algorithm with a non-obvious linear time complexity.
This problem is typically solved using Welzl's Algorithm.
Welzl(P, R) where P is the set of points and R is the set of points on the boundary of the circle.P is empty or |R| = 3, return the circle formed by R.p from P.D for P - {p}.p is inside D, return D.p must be on the boundary of the smallest circle. Return Welzl(P - {p}, R + {p}).Suppose you have a triangle of points.
Geometry problems are rare but high-stakes. If you are interviewing for a role involving graphics, maps, or physical systems, ensure you know the basics of circles, lines, and hulls.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Erect the Fence | Hard | Solve | |
| Convex Polygon | Medium | Solve | |
| Maximum Number of Darts Inside of a Circular Dartboard | Hard | Solve | |
| Queries on Number of Points Inside a Circle | Medium | Solve | |
| Self Crossing | Hard | Solve |