Notice Period

One Trade Window

easy

A vintage-guitar dealer gets a price forecast: prices[i] is what a certain guitar will cost on day i. She may buy it on one day and sell it on a later day — exactly one round trip.

Return the maximum profit she can lock in. If every sale would lose money, return 0 (she simply doesn't trade).

Example 1
in prices = [7, 1, 5, 3, 6, 4]
out 5
Buy at 1 (day 1), sell at 6 (day 4).
Example 2
in prices = [7, 6, 4, 3, 1]
out 0
Prices only fall — sitting out beats trading.
Constraints
  • · 1 <= len(prices) <= 2000
  • · 0 <= prices[i] <= 10^4
similar problem on LeetCode ↗
solution.pyloading python…
test results
Hit ▶ Run to test your code against the visible cases.