You are given an array of numbers, prices, where prices[i] is the price of a stock on day i.
Your task is to calculate the maximum profit achievable by buying a stock on one day and selling it on a subsequent day.
Note that:
Return the maximum profit possible. If no profit can be made, return 0.
[5, 3, 8, 6, 7, 11]
8
Buy on day 1 at price 3 and sell on day 5 at price 11 for a maximum profit of 8.
[10, 15, 4, 16, 12]
12
Buy on day 2 at price 4 and sell on day 4 at price 16 for maximum profit of 12.
[1, 7, 5, 10, 6]
9
Buy on day 0 at price 1 and sell on day 3 at price 10 for maximum profit of 9.
[20, 18, 15, 12, 10]
0
All prices decrease, so no profit can be made.
[8, 2, 5, 10, 12, 16, 7]
14
Buy on day 1 at price 2 and sell on day 5 at price 16 for maximum profit of 14.
[5, 3, 8, 6, 7, 11]
8