LeetCode 121 Best Time to Buy and Sell Stock - Problem Statement

The problem

You're given an array prices where prices[i] is the price of a stock on day i. You want to maximize profit by buying on one day and selling on a later day.

With prices = [7, 1, 5, 3, 6, 4], the answer is 5. Buy on day 2 (price 1) and sell on day 5 (price 6) for profit 6 - 1 = 5.

You can only hold one share at a time, and you must buy before you sell. What's the maximum profit you can achieve?

Constraints: 1n1051 \le n \le 10^5, prices from 00 to 10410^4.