Interleaving String

Given strings s1, s2, and s3, return true if s3 is an interleaving of s1 and s2. Every character from s1 and s2 must be used exactly once, while preserving the order inside each source string. Pattern focus: Interleaving strings. This is the standard 2D DP formulation of the interleaving check.

Input Format

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

Output Format

true if s3 can be formed by interleaving s1 and s2

Constraints

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

Examples

Example 1:

Input:

s1 = "abc"
s2 = "def"
s3 = "adbcef"

Output:

true

Explanation:

Characters from both strings are interwoven while preserving order.

Example 2:

Input:

s1 = "abc"
s2 = "def"
s3 = "abdecf"

Output:

false

Explanation:

The character order from the source strings is violated.

Loading...
Interleaving String - Dp Strings DSA Problem