Help with clarification

prob: https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/

In this question how are we supposed to handle the input because they are showing root = array of all the nodes of the tree and in the function they are passing the pointer of root node

You misunderstood it, here root is not equal to array, in first example root is equal to node having value 3, then p is equal to node having value 5 same is with q now you have to apply your logic here.

okay but on the left side they have showed it as an array so I thought…

I’m storing the path from root node to destination for both of the nodes and then traversing that path to find the lca but getting some error

this logic is absolutely fine, just issue with the implementation . Take reference from this


it’s same as of your code, notice the changes and apply it in your code.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.