Didnt find the difference

ll solve(ll n)
{
if(n==0 or n==1)
return n;
ll sum=0;

sum=sum+n;
solve(n-1);

return sum;

}

and
ll solve(ll n)
{
if(n==0 or n==1)
return n;
ll sum=0;

sum=sum+n+solve(n-1);

return sum;

}

please tell me how these two function work differently and how the call stack work in the two cases. please help i am highly confused

Hey in both the approaches stack call will be same.
Say st is stack
So when you reach n=1.
stack will be like this
stack(2)
stack(3)
.
.
.
stack(n)

The difference is the first function won’t return you the correct answer and it will only return you n as sum because u are not using calculation of solve(n-1).

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.