@@ -0,0 +1,1343 @@
+package com.interview.recursion;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0A/**%0A * Date 07/10/2015%0A * @author Tushar Roy%0A * %0A * Given an input and total print all combinations with repetitions in this input%0A * which sums to given total.%0A * e.g%0A * input - %7B2,3,5%7D %0A * total - 10%0A * %0A * Output%0A * %7B2,2,2,2,2%7D%0A * %7B2,3,5%7D%0A * %7B5,3,2%7D%0A * %7B5,2,3%7D%0A * %7B2,2,3,3%7D%0A * %7B3,3,2,2%7D%0A * and so on%0A *%0A */%0Apublic class PrintSumCombination %7B%0A%0A    public void print(int input%5B%5D, int sum) %7B%0A        boolean used%5B%5D = new boolean%5Binput.length%5D;%0A        List%3CInteger%3E result = new ArrayList%3C%3E();%0A        print(input, sum, result, 0, used);%0A    %7D%0A    %0A    private void print(int input%5B%5D, int sum, List%3CInteger %3Eresult, int pos, boolean used%5B%5D) %7B     %0A        if(sum %3C 0) %7B%0A            return;%0A        %7D%0A        if(sum == 0) %7B%0A            result.stream().forEach(i -%3E System.out.print(i + %22 %22));%0A            System.out.println();%0A            return;%0A        %7D%0A        %0A        %0A        for(int i=0; i %3C input.length; i++) %7B%0A            result.add(input%5Bi%5D);%0A            print(input, sum - input%5Bi%5D, result, pos+1, used);%0A            result.remove(result.size()-1);%0A        %7D%0A    %7D%0A    %0A    public static void main(String args%5B%5D) %7B%0A        int input%5B%5D = %7B2,3,5%7D;%0A        PrintSumCombination psc = new PrintSumCombination();%0A        psc.print(input, 10);%0A    %7D%0A%7D%0A

Print all combinations for given input and total