AC 2
- using DP with O(n) extra space