Pergunta de entrevista da empresa Fidelity Investments

Buy and sell stocks II, leetcode question