Challenge: Strings Interleaving

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

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. 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.


Three strings


A boolean

Sample input

m = "abd"
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 70+ hands-on prep courses.