528. Erect the Fence II

Given a 2D integer list trees, where each element trees[i] = [xi, yi] represents the position of the i-th tree in the garden.

The task is to enclose all the trees using the shortest possible length of rope, forming a perfect circular boundary. The enclosure is valid if every tree lies either inside or exactly on the boundary of the circle.

More precisely, you need to determine a circle with center (x, y) and radius r such that all trees are within or on the circle, and r is the smallest possible.

Return an array [x, y, r] representing the center and radius of the circle. Answers within 10^-5 of the actual values will be considered correct.

Example 1:

Input: trees = [[1,1],[2,2],[2,0],[2,4],[3,3],[4,2]]  

Output: [2.00000,2.00000,2.00000]  

Explanation:

The optimal circular fence has its center at (2, 2) with a radius of 2, enclosing all trees.

Example 2:

Input: trees = [[1,2],[2,2],[4,2]]  

Output: [2.50000,2.00000,1.50000]  

Explanation:

The smallest possible enclosing circle has its center at (2.5, 2) and a radius of 1.5.

Now Your Turn!

Pick the correct output for the given input

Input: trees = [[3,3],[6,6],[6,3],[3,6]]  

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= trees.length <= 3000
  • trees[i].length == 2
  • 0 <= xi, yi <= 3000

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
vector<double> outerTrees(vector<vector<int>>& trees) {
}
};
Test Case

Input:

Trees