From a sequence containing the history of the price of a stock, I want to calculate the maximum profit I could have made.
In this example, we have the history of a stock over a period: [10, 5, 31, 14, 27, 30]. The sequence is ordered by day. 10 for day 1 and 30 for day 6.
Result: I buy my stock on day 2 at 5 and sell it on day 3 at 31, my profit is : 31-5=26
Exercise:
- Write a program that takes as input any sequence and returns the maximum profit on that sequence.