Consider the function
void solve(int arr[],int ind,int sum,int n,int count)
{
if(ind==n){
if(sum>max)
max=sum;
}
else{
sum+=arr[ind];//sum
if(ind==n-1)
solve(arr,ind+1,sum,n,1);//1st call
if(ind==n-2 && count>1)
solve(arr,ind+2,sum,n,1);//2nd call
if(ind<n-1 && count<2){
count++;
solve(arr,ind+1,sum,n,count);//3rd call
}
if(ind<n-2)
solve(arr,ind+2,sum,n,1);//4th call
if(ind<n-3)
solve(arr,ind+3,sum,n,1);//5th call
}
}
I have no problem about the logic but am confused about the passing of the variables.I am not able to make out whether the integer sum+=arr[ind] //sum is passed as the same variable in every call or is it updated after every call of the function?