1 line code in python


return max(A)+min(A)


I love Python


That’s 2*(n-1) comparisons, constant,
The problem can be solved with a worst(n).


Can be more faster

return A[0]+A[-1]

Python use TimSort which is the fastest sorting algorithm in current time
and max() and min() function also uses sorting btw


TimSort worst case complexity is in O(nlogn). We can definitely do it in less than that. How about O(N)?

def solve(self, A):
    minn, maxx = sys.maxsize, -sys.maxsize
    for i in range(len(A)):
        if A[i] < minn:
            minn = A[i]
        if A[i] > maxx:
            maxx = A[i]
    return maxx+minn