Maximum profit earned by buying and selling shares
EASYGiven a list containing future prediction of share prices, find maximum profit that can be earned by buying and selling shares any number of times with constraint that a new transaction can only start after previous transaction is complete.
Example #1
Input
1 3 2 1 7
Output
8