Problem
You get three strings s1, s2 and s3. Return true if s3 is an interleaving of s1 and s2. Otherwise, return false.
An interleaving of two strings contains all the characters of both strings and no other characters. The characters of s1 keep their order in s3. The characters of s2 also keep their order in s3.
To build an interleaving, take characters one at a time from the front of s1 or from the front of s2.
Example 1
- Input:
- s1 = "ab", s2 = "xy", s3 = "axby"
- Output:
- true
- Explanation:
- Take
afroms1,xfroms2,bfroms1and thenyfroms2.
Example 2
- Input:
- s1 = "ab", s2 = "xy", s3 = "abyx"
- Output:
- false
- Explanation:
- In
s3,ycomes beforex. Ins2,xcomes beforey.
Example 3
- Input:
- s1 = "", s2 = "cat", s3 = "cat"
- Output:
- true
Constraints
- 0 <= s1.length, s2.length <= 100
- 0 <= s3.length <= 200
- s1, s2 and s3 have only lowercase English letters.
Follow-up
Find a solution that uses only O(s2.length) extra memory.
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 97. Interleaving String
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source