Sum of Maximum and Minimum Elements Problem Statement
Given an array ARR
of size N
, your objective is to determine the sum of the largest and smallest elements within the array.
Follow Up:
Can you achieve the above task using the least number of comparisons possible?
Input:
The first line contains an integer T
, the number of test cases.
For each test case, the first line contains an integer N
, representing the size of the array ARR
.
The second line contains N
space-separated integers, which are the elements of array ARR
.
Output:
For each test case, output the sum of the maximum and minimum elements in the array ARR
.
Example:
Input:
2
5
1 3 5 7 9
4
-10 4 7 19
Output:
10
9
Explanation:
In the first test case, the maximum is 9
and the minimum is 1
. Their sum is 10
.
In the second test case, the maximum is 19
and the minimum is -10
. Their sum is 9
.
Constraints:
1 ≤ T ≤ 10
1 ≤ N ≤ 10^5
-10^9 ≤ ARR[i] ≤ 10^9
Note:
You are not required to print anything; the function should handle processing the results.

AnswerBot
4mo
Find sum of maximum and minimum elements in an array with least number of comparisons.
Iterate through the array and compare elements in pairs to find maximum and minimum simultaneously.
Keep track of c...read more
Odjo Junior
9mo
Divide and Conquer The idea is to use a divide and conquer approach in order to reduce the number of comparisons. We divide the array into two equal parts and find the maximum and minimum element of e...read more
Odjo Junior
9mo
SortingSort the array so that the 0th element will be the minimum value of the array and the last element will be the maximum value present in out array.Space Complexity: O(1)Explanation: O(1) In...
Anonymous
9mo
First I initialized two variables max and min.
and traverse the array to find max and min.
then return the sum of max and min.
Chejarla Ramya
2y
oo full form is object oriented.
Add answer anonymously...
ZeMoSo Technologies Software Developer Intern interview questions & answers
A Software Developer Intern was asked Q. What are the SQL query basics?
A Software Developer Intern was asked Q. Structure in c++
A Software Developer Intern was asked Q. Least common ancestors tree
Popular interview questions of Software Developer Intern
A Software Developer Intern was asked Q1. What are the SQL query basics?
A Software Developer Intern was asked Q2. Structure in c++
A Software Developer Intern was asked Q3. Least common ancestors tree
>
ZeMoSo Technologies Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

