Skip to content

Commit 06da4df

Browse files
committed
Adding readme file
1 parent 67e9c76 commit 06da4df

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

97-InterleavingString/README.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Given strings s1, s2, and s3, find whether s3 is formed by an interleaving of s1 and s2.
2+
3+
An interleaving of two strings s and t is a configuration where s and t are divided into n and m substrings respectively, such that:
4+
5+
6+
s = s1 + s2 + ... + sn
7+
t = t1 + t2 + ... + tm
8+
|n - m| <= 1
9+
The interleaving is s1 + t1 + s2 + t2 + s3 + t3 + ... or t1 + s1 + t2 + s2 + t3 + s3 + ...
10+
11+
12+
Note: a + b is the concatenation of strings a and b.
13+
14+
 
15+
Example 1:
16+
17+
Input: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"
18+
Output: true
19+
Explanation: One way to obtain s3 is:
20+
Split s1 into s1 = "aa" + "bc" + "c", and s2 into s2 = "dbbc" + "a".
21+
Interleaving the two splits, we get "aa" + "dbbc" + "bc" + "a" + "c" = "aadbbcbcac".
22+
Since s3 can be obtained by interleaving s1 and s2, we return true.
23+
24+
25+
Example 2:
26+
27+
Input: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbbaccc"
28+
Output: false
29+
Explanation: Notice how it is impossible to interleave s2 with any other string to obtain s3.
30+
31+
32+
Example 3:
33+
34+
Input: s1 = "", s2 = "", s3 = ""
35+
Output: true
36+
37+
38+
 
39+
Constraints:
40+
41+
42+
0 <= s1.length, s2.length <= 100
43+
0 <= s3.length <= 200
44+
s1, s2, and s3 consist of lowercase English letters.
45+
46+
47+
 
48+
Follow up: Could you solve it using only O(s2.length) additional memory space?

0 commit comments

Comments
 (0)