dp
with dimensions (len(s1)+1) x (len(s2)+1)
.dp[0][0]
to true
as an empty string is an interleaving of two empty strings.dp
based on whether previous characters of s1
or s2
match with s3
.dp
table starting from dp[1][1]
.dp[i][j]
, set it to true
if either dp[i-1][j]
is true
and s1[i-1]
matches s3[i+j-1]
, or dp[i][j-1]
is true
and s2[j-1]
matches s3[i+j-1]
.dp[len(s1)][len(s2)]
.