title: Interleaving of two strings
body: <p>I have two strings <code>str1</code> and <code>str2</code>. 
  Is there any algorithm that can be used in order to print out all interleavings of the two strings using recursion?</p>
  
  <p>Update:</p>
  
  <pre><code>public class Interleave {
  
  
      private String resultString[] = new String[10];
      private String[] interStr(String str1, String str2){
      int n = ((Factorial.factorial(str1.length() + str2.length())) / (Factorial.factorial(str1.length()) * Factorial.factorial(str2.length())));
      //n is number of interleavings based on (str1.length()+str2.length())! / (str1.length()! * str2.length()!)
      if(str1.length() == 0){
          resultString[0] = str2;
          return resultString;
      }
  
      if(str2.length() == 0){
          resultString[0] = str1;
          return resultString;
      }
  
      else{
          for(int i = 0; i &lt; n; i++){
              resultString[i]= str1.substring(0, 1) + interStr(str1.substring(1), str2.substring(1));
  
          }
      }
      return resultString;
  }
  
      public static void main(String[] args) {
      Interleave obj = new Interleave();
      obj.interStr("12", "abc");
      for(int i = 0; i &lt; obj.resultString.length; i ++){
          System.out.println(obj.resultString[i]);
      }
  
  }
  
  }
  </code></pre>