Trains the technique from
LeetCode 122Best Time to Buy and Sell Stock IIThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A dealer trades one collectible and already knows what it will be quoted at on every trading day: quotes[i] is its price in whole credits on day i.
On each day the dealer may buy one copy, sell the copy currently held, or stand pat. Never more than one copy may be held at a time, so a copy has to be sold before another is bought, and a sale followed by a purchase on the same day is allowed. The dealer holds nothing before day 0 and must hold nothing once the last day closes.
Return the largest total profit available over the whole run.
Example 1
Buy on day 1 at 1 and sell on day 2 at 4 for 3 credits, then buy on day 3 at 2 and sell on day 4 at 8 for 6 credits, totalling 9.
Example 2
The quote never rises from one day to the next, so the dealer buys nothing and keeps a profit of 0.
Example 3
Hold from day 1 through day 3 for 3 credits, then from day 5 through day 6 for 5 credits; flat days add nothing either way.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def resale_profit(quotes: list[int]) -> int:public int resaleProfit(int[] quotes)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.