Take a look at the Efficient approach given under: https://www.geeksforgeeks.org/stock-buy-sell/
How can I use this approach if the question is changed to - you must