Maximum area of rectangle inscribed in an equilateral triangle
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:
Time complexity: O(1) as constant operations are done
Auxiliary Space: O(1)