@@ -0,0 +1,1490 @@
+package com.sunny.grokkingalgorithms.boot2019;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Apublic class GenerateCombinations %7B%0A%0A%0A    public static List%3CList%3CInteger%3E%3E generateCombinations(List%3CInteger%3E input)%7B%0A        if(input.isEmpty())%7B%0A            List%3CInteger%3E emptyList = new ArrayList%3C%3E();%0A            List%3CList%3CInteger%3E%3E combination = new ArrayList%3C%3E();%0A            combination.add(emptyList);%0A            return combination;%0A        %7D%0A        int cur = input.remove(0);%0A        List%3CList%3CInteger%3E%3E subList = generateCombinations(input);%0A        List%3CList%3CInteger%3E%3E combination = new ArrayList%3C%3E();%0A        if(subList.size() == 1)%7B%0A            List%3CInteger%3E curList = new ArrayList%3C%3E();%0A            curList.add(cur);%0A            combination.add(curList);%0A        %7Delse%7B%0A            for(List%3CInteger%3E sub : subList)%7B%0A                List%3CInteger%3E mod = new ArrayList%3C%3E();%0A                mod.addAll(sub);%0A                mod.add(cur);%0A                combination.add(mod);%0A            %7D%0A        %7D%0A        combination.addAll(subList);%0A        return combination;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        List%3CInteger%3E input = new ArrayList%3C%3E();%0A        input.add(1);%0A        input.add(2);%0A        input.add(3);%0A        System.out.println(generateCombinations(input));%0A        input = new ArrayList%3C%3E();%0A        input.add(1);%0A        input.add(2);%0A        input.add(3);%0A        input.add(4);%0A        System.out.println(generateCombinations(input));%0A    %7D%0A%0A%7D%0A

Generate combinations