Back to DSA
Interleaving String
hardThree strings s1, s2, and s3 are given. Determine whether s3 can be formed by interweaving the characters of s1 and s2, maintaining each string's internal character order but allowing characters from either string at each position.
Examples
Example 1:
Input:
s1 = "xy", s2 = "ab", s3 = "xayb"Output:
trueExplanation: Taking x from s1, a from s2, y from s1, b from s2 produces xayb.
Example 2:
Input:
s1 = "xy", s2 = "ab", s3 = "xyba"Output:
falseExplanation: No interleaving of 'xy' and 'ab' can produce 'xyba' because 'b' must come before 'a' in s2.
Hints
1234567