Given three strings s1, s2, and s3, determine whether s3 can be formed by interleaving s1 and s2 while preserving the relative order of characters from each.
s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"trues3 = "aadbbbaccc"falseSolve it in the editor. Sign in free to run your Python or JavaScript against test cases, get a verdict, and track your attempts.
Solve on FeatCode →The same DP idea as 1-D, but the state depends on two indices — often two positions in a grid, or a position in each of two sequences being compared.
Read the full 2-D Dynamic Programming guide →
Original problem on LeetCode ↗