← Discussions on Count Palindromic Substrings
S sreddy OFFICIAL
28 Jul 2026, 11:59

Clean C++ 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).

1 reply

okhan 2 months, 2 weeks ago

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

Sign in to reply.