Best buy-sell profit

Write codeEasy10 min

Your task

A sneaker resale app shows a pair's projected listing price for each of the next n days. You may buy the pair on one day and sell it on any later day, at most one buy and one sell. Return the largest profit you can lock in, or 0 if every buy-sell combination loses money (you can always choose not to trade). Example: prices [8, 3, 6, 4, 9] gives profit 6, buy at 3, sell at 9.

Examples

max_flip_profit(prices: list[int]) -> int
Example 1
Inputmax_flip_profit([8, 3, 6, 4, 9])
Output6