Definition of interleave on test examples


  • 1
    B
    The example says:
    s1 "aabcc"
    s2 "dbbca"
    s3 "aadbbcbcac" is interleave,
    
    if we decompose: s3
    "aa"   "db"  "bc"  "bc"  "a"  "c"
     s1     s2    s1    s2   s2    s1
    
    It is not interleaving right?

  • 4
    M

    You are somewhat correct, in that the decomposition you gave is not interleaving.
    On the other hand, the pattern

    s1 = aa-bc-c
    s2 = dbbc-a
    

    does work.

    aadbbcbcac   
    aa   dbbc   bc   a  c 
    s1 -  s2  - s1 -s2 -s1
    

    Interleaving does not mean that the segments must be the same length, only that by advancing in one string at a time, we can recreate s3.


  • 0
    Y

    why the case above is not interleaving? could you explain more?

    My understanding is as long as S3 is composed with S1, and S2 without reverse order, it should be OK. ("bc" "a" ) in S2 = :"bca", right?

    or it must be S1-s2 -s1-s2?
    can it be s2-s1-s2-s1?


  • 0
    S

    if we decompose : s3

    "aa" "db" "bc" "bca" "c"
     s1   s2   s1    s2   s1
    

    the example is interleave.


  • 0
    C

    This really helps! Thank you


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.