dp
of size (m+1) x (n+1)
where m
and n
are the lengths of s1
and s2
respectively.dp
with the cumulative ASCII sum of characters in s1
.dp
with the cumulative ASCII sum of characters in s2
.dp[1][1]
to dp[m][n]
.
s1[i-1] == s2[j-1]
, set dp[i][j] = dp[i-1][j-1]
.dp[i][j] = min(dp[i-1][j] + ord(s1[i-1]), dp[i][j-1] + ord(s2[j-1]))
.dp[m][n]
as the final result.