![]() |
VOOZH | about |
Given an array of n elements. Find maximum sum of pairwise multiplications. Sum can be larger so take mod with 10^9+7. If there are odd elements, then we can add any one element (without forming a pair) to the sum.
Examples:
Input : arr[] = {-1, 4, 5, -7, -4, 9, 0}
Output : 77
So to get the maximum sum, the arrangement will
be {-7, -4}, {-1, 0}, {9, 5} and {4}.
So the answer is (-7*(-4))+((-1)*0)+(9*5)+(4) ={77}.
Input : arr[] = {8, 7, 9}
Output : 79
Answer is (9*8) +(7) = 79.
Approach:
Implementation:
87
Time Complexity : O(N log(N))
Auxiliary Space: O(1)