L
likhithaheg1
OFFICIAL
13 Sep 2026, 17:11
Clean Python solution, beats most submissions.
Define dp[i] as the answer for the first i elements and write the transition from smaller states. Once it works, notice you only need the previous row/value, so space drops to O(1) or O(n).