1D / Linear DP pattern
First define what dp[i] means. Fill the smallest positions, then build forward until the final position contains the answer.
Difficulty: Easy · Approach: Save each smaller answer once
This is a public lesson preview. Sign in with a Lifetime Pass to open the protected animation, solution, and code.