Problem 65 of 75

Best Time to Buy and Sell Stock with Transaction Fee

MediumNot solved yetInterview me on this
Before you code · which pattern fits?

The problem

Given prices[i] (price on day i) and a transaction fee, you may complete as many transactions as you like (pay the fee per transaction, hold at most one share). Return the maximum profit.

(prices=[1,3,2,8,4,9], fee=2) → 8

Your solution runs against 2 unit tests, including edge and large-value cases.

Loading...

Test console · 2 unit tests

Submit your code to run it against all 2 unit tests. Results appear here.

JavaScript, TypeScript & Python run sandboxed in your browser; other languages run on the execution server. Your code is saved locally as you type.

Hint

Reference solution

Video explanation

Best Time to Buy and Sell Stock with Transaction Fee, explainedAlgorithms Made Easy