Given here is an equilateral triangle of side length a, which inscribes a hexagon which in turn inscribes a square. The task is to find the side length of the square.
Input: a = 6 Output: 2.538 Input: a = 8 Output: 3.384
We know the, side length of a hexagon inscribed within an equilateral triangle is h = a/3. Please refer Largest hexagon that can be inscribed within an equilateral triangle .
Also, the side length of the square that can be inscribed within a hexagon is x = 1.268h Please refer Largest Square that can be inscribed within a hexagon.
So, side length of the square inscribed within a hexagon which in turn is inscribed within an equilateral triangle, x = 0.423a.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
In case you wish to attend live classes with industry experts, please refer DSA Live Classes