MaxProfit is a problem where one must compute the maximum possible earnings given a log of stock prices. Note that before attempting this problem, you should read the material on maximum slice.

Our goal is to basically compute the maximum profit that ends in a given position. Thus, if we assume that the maximum profit that ends in a position *i* equals *maxProfit* then the maximum slice ending in position *i + 1* is going to be *max(0, maxProfit + (a _{i} - a_{i - 1}))*.

The full solution can be found here.