Back to Practice
#0303

Interleaving String

HardDSA40 min25 XP

Problem

Return True if s3 can be formed by interleaving s1 and s2 while preserving the character order of each source string.

Why This Matters

Interleaving String is a 2D DP problem where each state tracks how much of two sources has been consumed.

Function Signature

def is_interleave(s1, s2, s3):

Examples

Example 1
Inputs1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"
OutputTrue

s3 can be built by taking characters from s1 and s2 while preserving both orders.

Constraints

  • Return the exact requested value.
  • Handle edge cases cleanly.
  • Use the intended DSA pattern when brute force would scale poorly.
CodePython
Visible browser tests run here when available.
Testcases2 visible / 3 hidden categories
Valid interleave
Inputaabcc + dbbca
ExpectedTrue

A valid sequence of choices exists.

Invalid interleave
Inputaabcc + dbbca invalid target
ExpectedFalse

The target forces an order conflict.

Hidden Test Categories
empty stringslength mismatchrepeated ambiguous letters