Challenge: Strings Interleaving

Let's write code to find out if a given string is the result of interleaving two other strings

Problem statement

Give three strings m, n, and p, write a function to find out if p has been formed by interleaving m and n. ‘p’ should be considered to be an interleaved form of m and n if it contains all the letters from m and n with the order of the letters preserved.

Input

Three strings

Output

A boolean

Sample input

string m= "abd";
string n= "cef";
string p= "abcdef";

Sample output

True

Coding exercise

Take a close look and design a step-by-step algorithm first before jumping to the implementation. This problem is designed for your practice, so try to solve it on your own first. If you get stuck, you can always refer to the hint and solution provided in the code tab. Good Luck!

Note: The function below returns -1 as the default value. However, as mentioned above, in your solution you have to return a boolean value. You can keep the return type of the function as Object or change it to boolean.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.