Best Stock Profit With a Sell Fee
Problem statement
You may buy and sell one share any number of times, but may hold at most one share. Every sale pays a fixed sellFee. Return the maximum achievable profit.
A sale may occur only after its corresponding purchase.
Function
maxProfitWithSellFee(prices: int[], sellFee: int) → intExamples
Example 1
prices = [1,3,2,8,4,9]sellFee = 2return = 8Case 1 exercises the documented deterministic contract.
Example 2
prices = [1,3,7,5,10,3]sellFee = 3return = 6Case 2 exercises the documented deterministic contract.
Example 3
prices = [5]sellFee = 2return = 0Case 3 exercises the documented deterministic contract.
Constraints
1 <= prices.length <= 200000.0 <= prices[i], sellFee <= 10^6.- The answer fits a signed 32-bit integer.