Can someone please point out why the code giving WA for this problem http://www.spoj.com/problems/BST/
I have just calculated height of nodes : http://ideone.com/WhPKUe
Can someone please point out why the code giving WA for this problem http://www.spoj.com/problems/BST/
I have just calculated height of nodes : http://ideone.com/WhPKUe
I suppose you are printing something in the inorder function
void inorder(struct node *root)
{
if (root != NULL)
{
inorder(root->left);
printf("%d ", root->key); //here comment this one
inorder(root->right);
}
}
Also you are using a naive algorithm.You are using the implementation given in the problem statement which I think will fetch you a TLE. And use long long because your answer will overflow in “long”.