July 29, 2022 |5.5K Views

    Java Program to Print all Interleavings of given Two Strings

    Description
    Discussion

    In this video, we will see a JAVA program for Print all interleaving of given two strings. 

    So basically an interleaved string of given two strings preserves the order of characters in individual strings. For example, in all the interleaving of above first example, ‘A’ comes before ‘B’ and ‘C’ comes before ‘D’. 

    Examples: 
    String 1: AB 
    String 2: C
     
    Output: 
    ABC
    ACB 
    CAB 

    So, C is said to be interleaving A and B , if it contains all and only characters of A and B order of all characters in individual strings is preserved. 

    Input: 
    str1 = "WX", str2 = "YZ" 

    Output: 
    WXYZ 
    WYXZ 
    WYZX 
    YWXZ 
    YWZX 
    YZWX 

    Here the time complexity is O(2 ^ (m+n)). 

    Print all interleaving of given 2 strings:
    https://www.geeksforgeeks.org/print-all-interleavings-of-given-two-strings/