Best Time to Buy Stock

L4 Easy Sliding Window
Concept
Forward knowledge is everything here: the best day to sell only cares about the cheapest price you have already seen.
You know a stock price for each day in prices. You may buy on one day and sell on a strictly later day. Return the largest profit possible, or 0 if no profitable trade exists.
Examples
▸ prices = [7, 1, 5, 3, 6, 4]
→ 5
▸ prices = [7, 6, 4, 3, 1]
→ 0
▸ prices = []
→ 0
Progressive Hints
Hint 1 · Nudge
Track the lowest price you've seen; every later day is a chance to sell above it.
Hint 2 · Plan
Walk the prices once, remembering the cheapest price seen so far. At each day, the candidate profit is the current price minus that cheapest. Keep the best candidate profit and never let it drop below 0.
Hint 3 · Approach
lowest = a very large value, best = 0. For each p: lowest = the smaller of lowest and p, best = the larger of best and p - lowest. Return best.
Output
// Run your code to see the output here.