![]() |
VOOZH | about |
Given four sides of quadrilateral a, b, c, d, find the maximum area of the quadrilateral possible from the given sides .
Examples:
Input : 1 2 1 2
Output : 2.00
It is optimal to construct a rectangle for maximum area .
According to Bretschneider's formula, the area of a general quadrilateral is given by
Here a, b, c, d are the sides of a quadrilateral, s is the semiperimeter of a quadrilateral and angles are two opposite angles.
So, this formula is maximized only when opposite angles sum to pi(180) then we can use a simplified form of Bretschneider's formula to get the (maximum) area K.
This formula is called as Brahmagupta's formula .
Below is the implementation of given approach
Output:
2.00Time Complexity: O(logn)
Auxiliary Space: O(1)
Please suggest if someone has a better solution which is more efficient in terms of space and time.