return max(A)+min(A)
1 line code in python
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
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