Approach Summary
State machine DP: held, sold, rest. Transitions: held = max(prev_held, rest - price); sold = held + price; rest = max(prev_rest, prev_sold).
How to Recognize This Pattern
- State machine with cooldown constraint
- Three states: holding, just sold, resting
Complexity Analysis
Time Complexity
O(n)
Space Complexity
O(1)
Tags
Array Dynamic Programming