Challenge: Interleaving Strings
Check if a given string is the result of interleaving two other strings.
We'll cover the following
Problem statement
Given three strings m
, n
, and p
, write a function to find out if p
has been formed by interleaving m
and n
. Here, p
should be considered to be an interleaved form of m
and n
if it contains all the letters from m
and n
in a preserved order.
Input
Three strings.
Output
A boolean.
Sample input
m = "and";
n = "cef";
p = "abcdef";
Sample output
result = true;
Coding challenge
First, take a close look at this problem and design a step-by-step algorithm 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 solution provided in the solution section. Good luck!
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.