Given an integer A, which denotes the side of an equilateral triangle, the task is to find the maximum area of the rectangle that can be inscribed in the triangle.
Input: A = 10
Maximum area of rectangle inscribed in an equilateral triangle of side 10 is 21.65.
Input: A = 12
Maximum area of rectangle inscribed in an equilateral triangle of side 12 is 31.176.
Approach: The idea is to use the fact that interior angles of an equilateral triangle is 60o. Then, Draw the perpendicular from one of the side of the triangle and compute the sides of the rectangle with the help of below formulae
The length of Rectangle = (Side of Equilateral Triangle)/2
The breadth of Rectangle = sqrt(3) * (Side of Equilateral Triangle)/4
Then, Maximum area of the rectangle will be
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.