Optimal Algorithmic Approach
State-machine DP with three states.
Core Invariants & Edge Cases
- States: held (holding stock), sold (just sold), rest (cooldown over)
- Transitions: held = max(held, rest - price); sold = held + price; rest = max(rest, sold)
- Answer is max(sold, rest) after all prices