Best Time to Buy and Sell Stock with Transaction Fee

You are given an integer array prices where prices[i] is the price of a given stock on the ith 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 need to pay the transaction fee for each transaction.

Note:

  • You may not engage in multiple transactions simultaneously (you must sell the stock before you buy again).
  • The transaction fee is only charged once per transaction (either when you buy or sell).
Examples
Input: [[1,3,2,8,4,9],2]
Output: 8
Hints

Best Time to Buy and Sell Stock with Transaction Fee

You are given an integer array `prices` where `prices[i]` is the price of a given stock on the `i`th day, and an integer `fee` representing a transaction fee.