Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Stock Profit by Pavellver
def stock_profit(stock: list[int]) -> int:
if len(set(stock))<2:
return 0
maxp = 0
minp = stock[0]
for i in range(1, len(stock)):
maxp = max(maxp, stock[i] - minp)
minp = min(minp, stock[i])
return maxp
print("Example:")
print(stock_profit([3, 1, 3, 4, 5, 1]))
# These "asserts" are used for self-checking
assert stock_profit([2, 3, 4, 5]) == 3
assert stock_profit([3, 1, 3, 4, 5, 1]) == 4
assert stock_profit([4, 3, 2, 1]) == 0
assert stock_profit([6, 2, 1, 2, 3, 2, 3, 4, 5, 4]) == 4
assert stock_profit([1, 1, 1, 2, 1, 1, 1]) == 1
assert stock_profit([4, 3, 2, 1, 2, 1, 2, 1]) == 1
assert stock_profit([1, 1, 1, 1]) == 0
print("You are the best broker here! Click 'Check' to earn cool rewards!")
Feb. 26, 2023
Comments: