SUM AT K LEVEL : GENERIC TREE


It satisfied only 1 test case and shows Error for rest

Hey @mverma_be19

int sum(node*root,int k)
{
	static int s=0;
	if(root==NULL) //place this above other condition
	{
		return 0;//updated this 
	}
	if(k==0)
	{
		s=s+root->data;
		return s;
	}
	
   sum(root->left,k-1);
   sum(root->right,k-1);
   return s;
}

Okay right. Thank you! Marked as resolved.

1 Like

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.