Solving HackerRank Problem | Buy Sell Orders to Maximize Profit

Problem statement