Given here is an equilateral triangle of side length a. The task is to find the side of the biggest square that can be inscribed within it.
Input: a = 5 Output: 2.32 Input: a = 7 Output: 3.248
Approach: Let the side of the square be x.
Now, AH is perpendicular to DE.
DE is parallel to BC, So, angle AED = angle ACB = 60
In triangle EFC, => Sin60 = x/ EC => √3 / 2 = x/EC => EC = 2x/√3 In triangle AHE, => Cos 60 = x/2AE => 1/2 = x/2AE => AE = x
So, side AC of the triangle = 2x/√3 + x. Now,
a = 2x/√3 + x
Therefore, x = a/(1 + 2/√3) = 0.464a
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.