WHAT IS WRONG WITH MY CODE 1!

#include<bits/stdc++.h>
using namespace std;
class node{
public:
int data;
nodeleft;
node
right;

node(int d){
	data=d;
	left=NULL;
	right=NULL;
}

};

node* buildTree(){
int d, num;
cin>>d>>num;
if(num==0){
noderoot=new node(d);
root->left=NULL;
root->right=NULL;
return root;
}
else{
node
root=new node(d);
root->left=buildTree();
root->right=buildTree();
return root;
}
}
void print(node*root){
if(root==NULL){
return ;
}
cout<data<<" ";
print(root->left);
print(root->right);
return ;
}

int height(node*root){
if(root==NULL){
return 0;
}
int hl=height(root->left)+hl;
int hr=height(root->right)+hr;
return max(hl,hr)+1;
}

void sumAtKthLevel(node*root,int k,int& sum){
if(root==NULL){
return ;
}
if(k==1){
sum=sum+root->data;
return ;
}
sumAtKthLevel(root->left,k-1,sum);
sumAtKthLevel(root->right,k-1,sum);
return ;
}

int main(){
node*root=buildTree();
int k;
cin>>k;
int sum=0;
sumAtKthLevel(root,k+1,sum);
cout<<sum<<endl;
return 0;
}

Hello @gabbar_2229
there is small mistake in ur build tree .
u were not handling case when num==1.
check ur updated code here ->

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.