Best Stock Profit

The list prices stores a stock price for each day, and you may make exactly one buy and one sell. You must buy first and sell on a later day. Given prices, return the maximum profit you can make. If no profitable trade is possible, return 0.

Примеры

Ввод
[7, 1, 5, 3, 6, 4]
Вывод
5
Ввод
[7, 6, 4, 3, 1]
Вывод
0
Ввод
[1, 2, 3, 4, 5]
Вывод
4

Нужно реализовать

def max_profit(prices):

Теги

arraydp
PostgreSQLv16

Itt jelenik meg a kód futtatásának eredménye

Visible tests
1
Input
[7,1,5,3,6,4]
Expected5
2
Input
[7,6,4,3,1]
Expected0
3
Input
[1,2,3,4,5]
Expected4
4
Input
[2,4,1]
Expected2
5
Input
[]
Expected0
6
Input
[3]
Expected0
Focus radio
Paused · SomaFM · Fluid