Check Interleaving of Two Strings

Given strings s1, s2, and s3, return true if s3 is formed by interleaving s1 and s2. The relative order of characters from each input string must be preserved. Pattern focus: Interleaving strings. This is the entry-level feasibility check for the interleaving DP state.

Input Format

s1 = first string, s2 = second string, s3 = merged target string

Output Format

true if s3 is an interleaving of s1 and s2

Constraints

  • 0 <= s1.length, s2.length <= 200
  • s1, s2, s3 contain lowercase English letters.

Examples

Example 1:

Input:

s1 = "aabcc"
s2 = "dbbca"
s3 = "aadbbcbcac"

Output:

true

Explanation:

This is a standard valid interleaving example.

Example 2:

Input:

s1 = "aabcc"
s2 = "dbbca"
s3 = "aadbbbaccc"

Output:

false

Explanation:

The ordering constraint fails.

Loading...
Check Interleaving of Two Strings - Dp Strings