void insert(struct TreeNode* root,int a[],int *x){ if(root->left!=NULL) insert(root->left,a,x); a[*x]=root->val; (*x)++; if(root->right!=NULL) insert(root->right,a,x); } int KthNode(struct TreeNode* proot, int k ) { // write code here if(proot==NULL) return -1; int a[1000]; int x=1; for(int i=0;i<1000;i++) a[i]=-1; insert(proot,a,&x); if(a[k]==-1) return -1; else return a[k]; }