I have the following code from Print all unique integer partitions given an integer as input
void printPartitions(int target, int maxValue, String suffix) {
if (target == 0)
System.out.println(suffix);
else {
if (maxValue > 1)
printPartitions(target, maxValue-1, suffix);
if (maxValue <= target)
printPartitions(target-maxValue, maxValue, maxValue + " " + suffix);
}
}
When it calls printPartitions(4, 4, "");
it gives the below output:
1 1 1 1
1 1 2
2 2
1 3
4
How can I get the output in an array like this:
[[1,1,1,1],[1,1,2],[2,2],[1,3],[4]]