I need to find a way to remove duplicates from a combination like this:
Input: 3 and 2, where 3 is the range (from 1 to 3) and 2 is the length of each combinati
You can pass the last max value used into gen:
gen
private static void gen(int index, int minI) { if (index == result.length) { printArray(); return; } for (int i = minI; i <= n; i++) { result[index] = i; gen(index + 1, i); } }
And call it starting with 1: gen(0, 1);
1
gen(0, 1);