Solution for MaxProfit