Can someone please point out why the code giving WA for this problem SPOJ.com - Problem BST
I have just calculated height of nodes : WhPKUe - Online C++ Compiler & Debugging Tool - Ideone.com
Can someone please point out why the code giving WA for this problem SPOJ.com - Problem BST
I have just calculated height of nodes : WhPKUe - Online C++ Compiler & Debugging Tool - Ideone.com
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”.