Just two lines of c++ code


int Solution::solve(vector &A) {
return A[0]+A[A.size()-1];

// I have used stl
//but you can code sort function on your own
//merge sort will be good


Its will be O(n log (n)) while it’s can be easily O(n):

int Solution::solve(vector &A) {
int max= -1* pow(10,9);
int min= pow(10,9);
for(int i=0;i<A.size();i++){
if (A[i]>max)
max= A[i];
if (A[i]<min)
min= A[i];
return max+min;