Skip to content

Practice Interleaving String

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#97
LeetCode Problem

Interleaving String

Problem Statement

Given s1, s2 and s3, return whether s3 can be made by merging all characters from s1 and s2 while preserving the order of characters within each original string. Either string may provide the first character, and consecutive characters may come from the same string. Equivalently, split each input into pieces and alternate those pieces, with their counts differing by at most one. Follow-up: use only O(s2.length) additional memory.

Source: Interleaving String on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"
Output
true

# Example 2

Input
s1 = "aabcc", s2 = "dbbca", s3 = "aadbbbaccc"
Output
false

# Example 3

Input
s1 = "", s2 = "", s3 = ""
Output
true

Constraints

0 <= s1.length, s2.length <= 100
0 <= s3.length <= 200
s1, s2, and s3 consist of lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Interleaving String.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.