Interleaving String
Given strings s1, s2, and s3, determine whether s3 can be formed by interleaving s1 and s2. An interleaving keeps the relative order of characters within s1 and within s2 while merging them; every character of s1 and s2 must be used exactly once.
Open official problem prompt ↗Decide if the target string is an order-preserving merge of the two source strings, using each source character exactly once.
Two dealers each hold a fixed stack of cards. You build one output pile by repeatedly taking the top card from either stack. The question is whether some sequence of choices reproduces the target pile exactly.
- Input
- s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"
- Output
- true
- Why
- s3 can be split as (aa)(dbbc)(bc)(a)(c) alternating between s1's aabcc and s2's dbbca while preserving each string's order.
0 <= s1.length, s2.length <= 1000 <= s3.length <= 200s1, s2, and s3 consist of lowercase English letters