Why doesn't the variable inside the function update but when I print it outside it, it doesn't work. But if I do the same with ArrayList, the ArrayList gets updated. Why So???
public int perfectSum(int arr[],int n, int sum) 
    { 
        // Your code goes here
        int i = 0;
        helper(arr,sum,0,0,i);
        return i;
    } 
    void helper(int arr[], int target, int sum, int idx, int i){
        if(idx == arr.length){
            if(sum == target){
                i++;
            }
            return;
        }
        
        helper(arr, target, sum+arr[idx], idx+1, i);
        helper(arr, target, sum, idx+1, i);
    }
 
     
    