1 line code in python


#1

return max(A)+min(A)


#2

:joy::joy::joy:
I love Python


#3

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


#4

Can be more faster

sort(A)
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


#5

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