Implement a solution to find the maximum profit from a series of asset values, optimizing for both time and memory efficiency.