Interleaving String
Problem 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 source strings while retaining each source's internal order.
Example 2
s1 = "aabcc"s2 = "dbbca"s3 = "aadbbbaccc"return = falseEvery possible choice eventually needs to reverse or skip a character from one source, so the target is not an interleaving.
Example 3
s1 = ""s2 = ""s3 = ""return = trueThe empty target uses every character from both empty source strings.
Constraints
0 <= s1.length, s2.length <= 100.0 <= s3.length <= 200.- All three strings contain only lowercase English letters.