Skip to content
Onsite

Interleaving String

MediumP3Coding

Return true if s3 can be formed by interleaving s1 and s2: merging them into one string by taking characters from either string one at a time, while keeping the left-to-right order of the characters inside each string. Every character of both strings must be used exactly once.

Example 1

Input
s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"
Output
true
Why
One valid interleaving exists.

Example 2

Input
s1 = "aabcc", s2 = "dbbca", s3 = "aadbbbaccc"
Output
false
Why
No interleaving produces this string.

Example 3

Input
s1 = "", s2 = "", s3 = ""
Output
true

Constraints

  • 0 <= s1.length, s2.length <= 100
  • 0 <= s3.length <= 200
  • All strings contain lowercase English letters.

Hints

Run checks the 3 visible tests, Submit all 11.