prices[i] is a share price on day i. Write max_profit(prices) — the best profit from buying once and selling later (0 if no profit is possible).
max_profit([7, 1, 5, 3, 6, 4]) → 5
max_profit([7, 6, 4, 3, 1]) → 0
Submit runs 5 tests, including hidden edge cases.
Run your code to see the output here.