help needed in solving LCA !!!

here is d link to my code : https://www.codechef.com/viewsolution/14765517
im getting RE …can anyone say why its giving RE ??

Hey, just clarify one thing.

The question stated that-

Given a **tree** of N vertices,

So, it can be any tree. Why did you used node as-

struct node
{
  ll data;
  node *left;
  node *right;
};

What if the node has more than 2 children (as it can be any tree, and not necessarily a binary tree). I think that for inputs where a node has more than 2 children, your code can throw exception.

To find LCA in general Tree, this link should help:

yeah…i thought it as binary tree !
clarified !!

1 Like

Hope you get an AC soon enough then :smiley:

//