Simple O(n) solution to the given problem


#1

Comment body goes here.int Solution::solve(vector &A) {
int mx = A[0],mn = A[0];
int n = A.size();
if(n==1)
return mx+mn;
for(int i=1;i<n;i++){
mx = max(mx,A[i]);
mn = min(mn,A[i]);
}
return mx+mn;
}


#2

This is 2n comparisons.The question is to minimise number of comparisons not complexity.