interleaving

Find Interleaving Strings using Dynamic Programming

Introduction This problem is already discussed in the post here. This post attempts to solve the same using the dynamic programming approach. Here is a brief description of the problem. Given three strings A, B and C such that A is "ab", B is "ade" and C is "adabe" find if C is an interleaving of A and B or not. Interleaving means constructing the third string C using the characters of A and B such that the characters in A and B preserve their relative ordering in C. In the above example C is an interleaving of A and B. Approach to Find Interleaving Strings using Dynamic Programming How ...
Read More

Solution to find Interleaving of Strings

Introduction This post is an enhancement over one of the previous posts where the task was to find if a given string C is an interleaving of strings A and B. To know more about the problem description, please visit the previous post Solution The previous solution is a iterative solution which requires lot of space. Here we will discuss a recursive solution. Hopefully with small code foot print. Before we jump into the code, let us understand the idea behind the solution. Here are the example Strings A, B and C A -> abcd B -> ade C -> abadcde The recursive algorithm...
Read More