Stock Maximize Time : O(n) Space : O(1) 1234567def stockmax(A): res = 0 ma = 0 for i in range(len(A) - 1, -1, -1): res += max(ma - A[i], 0) ma = max(ma, A[i]) return res