Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 + 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 12Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started