Problem · String
Interleaving String
Learn this problemProblem statement
Given strings s1, s2, and s3, return whether s3 can be formed by interleaving s1 and s2.
An interleaving uses every character from both source strings exactly once while preserving the left-to-right order within each source. Characters chosen from the two sources may alternate in groups of any positive length.
Function
isInterleave(s1: String, s2: String, s3: String) → booleanExamples
Example 1
s1 = "aabcc"s2 = "dbbca"s3 = "aadbbcbcac"return = trueThe target can choose characters from both sources while retaining each source's internal order.
Example 2
s1 = "aabcc"s2 = "dbbca"s3 = "aadbbbaccc"return = falseNo sequence of source choices can produce the target without reversing or skipping a source character.
Example 3
s1 = ""s2 = ""s3 = ""return = trueThe empty target is the interleaving of two empty strings.
Constraints
0 <= s1.length, s2.length <= 100.0 <= s3.length <= 200.- All strings contain only lowercase English letters.