Best time to buy and sell stock (JavaScript and Python)