Tap here to switch tabs
Problem
Submissions

Problem: Best Time to Buy and Sell Stock with Transaction Fee

med
30 min
Try to solve the Best Time to Buy and Sell Stock with Transaction Fee problem.

Statement

You are given an integer array prices where prices[i] is the stock price on day i, and an integer fee representing a transaction fee charged each time you sell.

You may complete as many transactions as you want, but you can hold at most one share of the stock at any time, meaning you must sell before you buy again.

Return the maximum profit you can achieve. The transaction fee fee is paid once per transaction, at the time of selling.

Constraints:

  • 1≤1 \leq prices.length ≤5⋅104\leq 5 \cdot 10^4

  • 1≤1 \leq prices[i] <5⋅104< 5 \cdot 10^4

  • 0≤0 \leq fee <5⋅104< 5 \cdot 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Best Time to Buy and Sell Stock with Transaction Fee

med
30 min
Try to solve the Best Time to Buy and Sell Stock with Transaction Fee problem.

Statement

You are given an integer array prices where prices[i] is the stock price on day i, and an integer fee representing a transaction fee charged each time you sell.

You may complete as many transactions as you want, but you can hold at most one share of the stock at any time, meaning you must sell before you buy again.

Return the maximum profit you can achieve. The transaction fee fee is paid once per transaction, at the time of selling.

Constraints:

  • 1≤1 \leq prices.length ≤5⋅104\leq 5 \cdot 10^4

  • 1≤1 \leq prices[i] <5⋅104< 5 \cdot 10^4

  • 0≤0 \leq fee <5⋅104< 5 \cdot 10^4