@@ -0,0 +1,1611 @@
+package com.sunny.grokkingalgorithms.ctci.c9plusdp;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0A/**%0A * Created by sundas on 3/25/2018.%0A */%0Apublic class FindAllSubsetsOfASet %7B%0A%0A  /*%0A  Find all subsets of a set%0A   */%0A%0A  /**%0A   *%0A   * @param input*%0A   * @return%0A   */%0A  public static List%3CList%3CInteger%3E%3E findAllSubsetsOFASet(List%3CInteger%3E input)%7B%0A    if(input ==  null %7C%7C input.size() %3C= 0)%7B%0A      List%3CList%3CInteger%3E%3E subsets = new ArrayList%3C%3E();%0A      List%3CInteger%3E subset = new ArrayList%3C%3E();%0A      subsets.add(subset);%0A      return subsets;%0A    %7D%0A    int current = input.remove(0);%0A    List%3CList%3CInteger%3E%3E subsets = new ArrayList%3C%3E();%0A    //for(int i = 0; i %3C input.size() ; i++)%7B%0A      List%3CList%3CInteger%3E%3E children = findAllSubsetsOFASet(input);%0A      if(children != null)%7B%0A        if(children.isEmpty())%7B%0A          List%3CInteger%3E prependList = new ArrayList%3C%3E();%0A          prependList.add(current);%0A          subsets.add(prependList);%0A        %7D%0A        else %7B%0A          for (List%3CInteger%3E child : children) %7B%0A            List%3CInteger%3E prependedChild = new ArrayList%3C%3E(child);%0A            prependedChild.add(0,current);%0A            subsets.add(prependedChild);%0A          %7D%0A          subsets.addAll(children);%0A        %7D%0A      %7D%0A    //%7D%0A    return subsets;%0A  %7D%0A%0A%0A  /**%0A   *%0A   * @param args%0A   */%0A  public static void main(String%5B%5D args) %7B%0A    List%3CInteger%3E set = new ArrayList%3C%3E();%0A    set.add(1);%0A    set.add(2);%0A    set.add(3);%0A    set.add(4);%0A    set.add(5);%0A    List%3CList%3CInteger%3E%3E subsets = findAllSubsetsOFASet(set);%0A    System.out.println(subsets);%0A    System.out.println(subsets.size());%0A  %7D%0A%0A%7D%0A

Find all subsets of a set