Buy and sell stock onceEasy
Let's say you're an ambitious stock trader.
But you only want to make one big trade in a given day.
You're given an array of stock prices, ordered by time. You can make one trade by buying at a particular price, and selling at another price.
Write a function that returns the max profit from one trade.
Note that you can't buy and sell a stock on the same day.
For example, given the input
[3, 1, 4, 5, 2, 9, 5, 3, 6]
Your function should return:
You can do this in constant space.
8 # Buy at 1, Sell at 9