leftover: DP, use O(N) extra space