Trains the technique from
LeetCode 714Best Time to Buy and Sell Stock with Transaction FeeThis 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 scrap yard trades a single bale of copper at a time. quotes[i] is the price the bale
fetches on day i, and every completed sale is charged a flat handling fee of commission.
The yard may trade as often as it likes but never holds two bales: a purchase is only allowed with the yard clear, and a sale is only allowed with a bale on the ground. Buying and selling on the same day is permitted. The handling fee is charged once per sale, never on a purchase. A bale still on the ground when the days run out is simply left there and earns nothing.
Return the largest net cash position the yard can finish with, counting each sale as its price minus the purchase price minus the handling fee. Trading nothing at all leaves 0.
Example 1
Buy at 4 and sell at 11, then buy at 6 and sell at 12. The two sales bring in 7 and 6 before fees, and the two fees of 3 leave 7.
Example 2
Buy at 1 on day 0 and sell at 6 on day 3. That is 5 before the fee and 3 after the single fee of 2.
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 net_resale_gain(quotes: list[int], commission: int) -> int:public int netResaleGain(int[] quotes, int commission)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.