solution for interview cake max profit for stock prices problem