Best Time to Buy and Sell Stock with Transaction Fee

You are given an array prices where prices[i] is the price of a stock on the i-th day and an integer fee representing a transaction fee. Find the maximum profit you can achieve. You may complete as many transactions as you like, but you must pay the transaction fee for each transaction and cannot engage in multiple transactions at the same time.

Constraints

  • 1 <= prices.length <= 5 * 10^4
  • 1 <= prices[i] < 5 * 10^4
  • 0 <= fee < 5 * 10^4
Saving… · 3 lines
class Solution:
def maxProfitWithTransactionFee(self, prices: List[int], fee: int) -> int:

Console

Click Run to execute sample tests.