Solution: Erect the Fence
Explore how to find the convex hull enclosing a set of points by applying the Monotone Chain algorithm. Understand sorting, orientation checks with cross products, and constructing lower and upper hulls to build the minimal perimeter fence around points. This lesson helps you implement an efficient geometric solution critical for coding interviews.
We'll cover the following...
Statement
You are given an array of points, trees, where trees[i] = [xᵢ, yᵢ] represents the location of a tree on a 2D plane. Your goal is to enclose all the trees using the shortest possible length of rope, forming a fence around the garden. A garden is considered well-fenced if every tree lies inside or on the boundary of the fence (i.e., the fence forms the
Return the coordinates of the trees that lie exactly on the fence perimeter. You can return the answer in any order.
Constraints:
trees.lengthtrees[i].length==xi,yi...