Can you do the above task in a minimum number of comparisons?
The first line of input contains a single integer T, representing the number of test cases.
Then the T test cases follow.
The first line of each test case contains a single integer N representing the size of the array 'ARR'.
The second line of each test case contains N space separated integers representing the elements of the array “arr”.
For each test case, print the sum of the maximum and minimum element of the array 'ARR'.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 10^5
-10^9 <= ARR[i] <= 10^9
Time limit: 1 second
Steps:
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 each part recursively. Then we compare the maximum and minimum of both parts in order to find the maximum and minimum element of the whole array.
Steps:
pair<int, int> findMaxMin(arr, left, right):
Missing Number
Longest Subarray With Zero Sum
Merge Two Sorted Arrays Without Extra Space
Ninja And The Strictly Increasing Array
Negative To The End