Best time to buy and sell stock

buy comes before sell.
“Find i and j that maximizes Aj – Ai, where i < j.”