Skip to content

Interleaving String

MediumDynamic Programming
Decode it first. Clues, constraints, pattern and plan before any code.

Return true if s3 can be formed by interleaving s1 and s2: splitting both into pieces and merging the pieces so that each string's characters keep their original order. Every character of s1 and s2 must be used exactly once.

s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"  →  true
s1 = "aabcc", s2 = "dbbca", s3 = "aadbbbaccc"  →  false
s1 = "",      s2 = "",      s3 = ""            →  true

Constraints

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