Find the maximum profit from one buy and one sell of a stock over a sequence of daily prices.
You are given an array prices where prices[i] is the stock price on day i.
You may complete at most one transaction: buy one share on one day and sell that share on a later day.
Return the maximum profit you can achieve. If no profitable transaction exists, return 0.
prices.prices[i] represents the stock price on day i.1 <= prices.lengthExample 1
Input
prices = [7,1,5,3,6,4]
Output
5
Explanation
Buy on day 2 at price 1 and sell on day 5 at price 6 for a profit of 5.
Example 2
Input
prices = [7,6,4,3,1]
Output
0
Explanation
Prices only decrease, so no profitable transaction exists.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.