prices[i] is what one gold coin costs at the market on day i. You are allowed a single round trip: buy one coin on some day and sell it on a later day. Return the most money that round trip can make. If every possible round trip would lose money or only break even, you stay out of the market and the answer is 0.
Examples
Input: prices = [9, 4, 6, 2, 8, 5]
Output: 6
Explanation: Buy on day 3 (price 2) and sell on day 4 (price 8).
Input: prices = [10, 8, 8, 5, 2]
Output: 0
Explanation: Prices only fall, so no trade makes money.
Constraints
- Target: O(n) time, O(1) extra space.
Goals
- Track the smallest value seen so far while scanning
- Update a best answer from the current element and the running minimum
- Return 0 when no profitable trade exists