Given daily prices, find the max profit from a single buy followed by a later sell.
Spotting a single-pass greedy (track a running minimum) instead of comparing every pair O(n²).
Sweep once, tracking the minimum price seen so far; at each day the best profit if you sold today is price - minSoFar, so keep the max of those. Greedy is correct because the optimal sell day depends only on the cheapest day at or before it — you never need to reconsider earlier decisions. Signal: 'best value relative to a running extreme' or 'one transaction' → maintain a running min/max in a single sweep rather than nested loops. Watch the constraint that you must buy before you sell, so profit never goes below 0.
'Max profit / one transaction', running min or max, any problem reducible to comparing each element to a running extreme.
Time O(n), Space O(1)