Query : This code is passing only custom test case and failing all other test cases.
#include<bits/stdc++.h>
using namespace std;
class node{
public:
int data;
nodeleft;
noderight;
node(int d)
{
data=d;
left=NULL;
right=NULL;
}
};
nodebuildTree()
{
int d;
cin>>d;
noderoot=new node(d);
int children;
cin>>children;
if(children==2)
{
root->left=buildTree();
root->right=buildTree();
}
else if(children==1)
{
root->left=buildTree();
}
return root;
}
int sumAtK(node*root,int k)
{
if(k==0)
{
return root->data;
}
if(root==NULL)
{
return 0;
}
return sumAtK(root->left,k-1)+sumAtK(root->right,k-1);
}
int main()
{
node*root=buildTree();
int k;
cin>>k;
cout<<sumAtK(root,k)<<endl;
return 0;
}