Question: Please answer fast in c++ or Java language. Given an array A of size N. Find the maximum value of the expression a*b + a

 Please answer fast in c++ or Java language. Given an array

A of size N. Find the maximum value of the expression a*b

Please answer fast in c++ or Java language.

Given an array A of size N. Find the maximum value of the expression a*b + a - b where a and b are 2 distinct elements of the array. Input: First line will contain T, number of testdases. Then the testcases follow. Each testcase contains of two lines of input. First line will contain N, number of elements of the array. Second line contains N space separated integers, elements of the array A Output: For each testcase, output in a single line answer to the problem. Constraints . 1 T 20 2 N 10 10 10 Sample Input: 2 2 22 3 5 3 2 Sample Output: 4 17 Explanation Case 1: Only possible pair is 2,2] for which answer = 2 * 2 + 2 2 = 4. Case 2: There are six possible pairs. For pairs 2,3 and 3.2), answer = 2 + 3 + max(2 - 3,3 - 2) = 7 For pairs 3.51 and 5.3 answer = 53 -- mar( 35.5 3) = 17 and For the pain 12

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!