Best Stock Profit

Imagine a stock price chart where you may choose one day to buy and a later day to sell. Given a list prices, where prices[i] is the price on day i, find the maximum profit you can make with one transaction. If no profit 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: list[int]) -> int:

Теги

arraydp
PostgreSQLv16

Šeit parādīsies koda izpildes rezultāts

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
[3,3,3]
Expected0
6
Input
[8,2,6,4,7,5]
Expected5
Focus radio
Paused · SomaFM · Fluid