MaxProfit solution