With n number of comparision


if the particular is greater than the previous max then it can’t be the minimum and vice versa hence it will take n comparison in for loop
int Solution::solve(vector &A) {
int n=A.size();
int max=A[0];
int min=A[0];
for(int i=1;i<n;i++)
else if(min>A[i])
return (max+min);


Your code will take 2*n comparisons for the worst case of an array to be [5,4,3,2,1].