You are given an array `prices` where `prices[i]` is the price of a stock on day `i`, and an integer `fee` representing a transaction fee. Find the maximum profit. You may complete as many transactions as you like, but you must pay the `fee` for each transaction. You may not buy and sell on the same day. **Example:** Input: `prices = [1,3,2,8,4,9]`, `fee = 2` Output: `8` Explanation: Buy at 1, sell at 8 (profit 5). Buy at 4, sell at 9 (profit 3). Total = 8.
Two-State DP
Track two states per day: `hold` (max profit while holding a stock) and `cash` (max profit without a stock). Transition: hold = max(hold, cash - price); cash = max(cash, hold + price - fee).