CME Group interview question

Stock Buy and Sell question from Leet code