Interleaving String

Medium#97two strings

You get three strings a, b and c. Find out whether c can be woven from a and b: every letter of both used exactly once, each string's letters kept in their order, a's and b's letters mixed in any way. Our example: "acab" from "ab" and "ac" — true: a and c from "ac", then a and b from "ab".

input
s1, s2, s3: three strings.
returns
true if s3 is an interleaving of s1 and s2: all their letters, each string's letters in their own order; false if not.
constraints
  • 0 ≤ s1.length, s2.length ≤ 100
  • 0 ≤ s3.length ≤ 200
  • s1, s2, s3: lowercase English letters
our 14 tests keep to them
examples
Open a test in the tests panel: it shows the input and the expected answer.
/**
 * @param {string} s1
 * @param {string} s2
 * @param {string} s3
 * @return {boolean}
 */
function isInterleave(s1, s2, s3) {

}
Ctrl ↵
format
reset

saved in this browser

14 tests · limit 3 s

Stuck?

See the solution run step by step on our example, then why it works and its complexity.

Watch the walkthrough →

Next: more dynamic programming (dp) problems

Pattern “Dynamic programming (DP)” →

The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.