Given an array where is the stock price on day , find the maximum profit from one buy and one sell.
You must buy before you sell.
For example, gives profit (buy at , sell at ).
This looks like a search problem, but you can solve it greedily.
Think about what you need to track as you scan through prices. Constraint: . Checking all time using space buy-sell pairs times out.