A non-empty array A consisting of N numeric values is
given.
The product of quadruplet (P, Q, R, S) equates to A[P]*
A[Q] * A[R] * A[S]
(
OP<Q <R<S<N).
For example, array A such that:
A[2] = 2
A[3] = -2
A[4] = 5
A[0] = -3
A[5] = 6
A[1] = 1
A[6] = 1
• (0, 1, 2, 3), product is -3*1*2*-2 = 12
• (1, 2, 4, 5), product is 1*2*5*6 = 30
.
• (2, 4, 5, 6), product is 25 1 6 1 60
60 is the product of quadruplets (2, 4, 5, 1), which is
maximal.
Answers
Answered by
3
Answer:
the function should return 60, as the product of triplet (2, 4, 5) is maximal.
Write an efficient algorithm for the following assumptions:
N is an integer within the range [3..100,000];
each element of array A is an integer within the range [−1,000..1,000].
Similar questions