← Discussions on Decode Ways
Y ybhat OFFICIAL
09 Sep 2026, 05:10

Why does my solution TLE on the last test case?

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).

3 replies

nithya.s 1 month, 1 week ago

Nice. Got asked a variant of this in an interview.

ndeshpande 1 month ago

Thanks! The dry run on the second example made it click.

hkapoor 1 month ago

Thanks! The dry run on the second example made it click.

Sign in to reply.