You are given an 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. 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 (i.e., you must sell the stock before you buy again). - The transaction fee is only charged once for each stock purchase and sale.
Example 1
Input: prices = [1,3,2,8,4,9], fee = 2
Output: 8
Explanation: Buy at 1 and sell at 8 for 8 - 1 - 2 = 5, then buy at 4 and sell at 9 for 9 - 4 - 2 = 3. The total profit is 5 + 3 = 8.
Example 2
Input: prices = [1,3,7,5,10,3], fee = 3
Output: 6
Explanation: One trade, buy at 1 and sell at 10, earns 10 - 1 - 3 = 6. Splitting it (1→7 and 5→10) earns only 3 + 2 = 5 because the fee is paid twice.
Example 3
Input: prices = [1,4,6,2,8,3,10,14], fee = 3
Output: 13
Explanation: Three trades work best: 1→6 earns 6 - 1 - 3 = 2, 2→8 earns 8 - 2 - 3 = 3, and 3→14 earns 14 - 3 - 3 = 8. The total is 2 + 3 + 8 = 13.
Track two running bests each day: cash = most money with NO share in hand, hold = most money while holding one share. Selling pays the fee once. Roll both forward day by day; the answer is the final cash.
Run checks all cases above. Submit evaluates all test cases.