Sum-of-k-smallest-elements-in-bst

1 solution wrong
void find_sum_key(Node *root,int *key,int *Sum){

if(root == NULL){
    return ;
}

//inorder 

find_sum_key(root->left,key,Sum);
*key = *key-1;
if(*key<0)
   return;
   
*Sum = *Sum + root->data;

find_sum_key(root->right,key,Sum);

}

2 solution right =>
void find_sum_key(Node *root,int *key,int *sum){

if(root == NULL){
    return ;
}
if(*key == 0 ){
    return;
}

//inorder 
find_sum_key(root->left,key,sum);
*sum = *sum + root->data;
*key = *key-1;
find_sum_key(root->right,key,sum);

}

I have provided two solutions of geeks for geeks problem
according to me both are right
when I dry run the both solution

but when I submitted 1 solution on geeks for geeks its wrong
but 2 solution right
I have confusion lot of “key” passing argument

can you dry run the both question with example

so I understand very well

example => 20 8 4 12 10 14 22 (bst value)
key = 3 (3 minimum element sum find)

@khemchandrs
Please send your code on CB IDE

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.