Question: An array A consisting of N integers is given. A triplet of indices ( P , Q , R ) is called a triangle if
An array A consisting of N integers is given. A triplet of indices PQR is called a triangle if P AR
AQ AR AP
AR AP AQ
The perimeter of such traingle equals AP AQ AR
For example consider the following array A:
A
A
A
A
A
A
Triplet iss a triangle and its perimeter equals There is no other triangle in this array with a larger perimeter.
Note that the inequality must hold between PQR but it is accepted that eg AP AQ consider the following array A:
A
A
A
A
A
Triplet is a triangle and its perimeter equals
Write a fucntion:
func SolutionA int int
that, given an array A on N integers returns the maximum perimeter of any triangle in this array. The function should return if there are no triangles. for example
A
A
A
A
A
A
the function should return as explained above. Given array A such that:
A
A
A
A
A
A
The function should return : the triangle with maximum perimeter is
While for an array A:
A
A
A
The function should return as it is impossible to create a triangle.
and for an array A:
A
A
A
A
A
the function should return as explained above.
Write an efficient algorithm for followiing assumption:
N is an integer within the range ;
each element of array A is an integer within the range
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
