I dont understand why we have used this condition
(βi==lastIndex || arr[i] != arr[i - 1])β in the code given below
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int arr[] = new int[n];
boolean[] index = new boolean[n];
for (int i = 0; i < n; i++) {
arr[i] = s.nextInt();
}
Arrays.sort(arr);
int amount = s.nextInt();
sumItUp(arr, 0, amount, "", 0, index);
}
public static void sumItUp(int[] arr, int amount, int tar, String ans, int lastIndex, boolean[] index) {
if (amount == tar) {
System.out.println(ans);
return;
}
for (int i = lastIndex; i < arr.length; i++) {
amount += arr[i];
if (amount <= tar && (i == lastIndex || arr[i] != arr[i - 1])) {
// if (amount >= arr[i]) {
// index[i] = true;
sumItUp(arr, amount, tar, ans + arr[i] + " ", i + 1, index);
// index[i] = false;
}
amount = amount - arr[i];
}
}
}