Lowest common ancestor

having trouble in understanding can anyone explain it in simpler way why we are taking custom class and what are the benefits of that??

@shampblocks I can provide a simpler code but it will have a few more iteration. Custom class is not necessarily needed here it just helps a bit.

Provide it sir… It will be helpful…

But this code is not taking care of the fact that if one of the elements are absent??

@shampblocks for that you will need to add a extra line and check the size of path, if size of path is zero of any node then no LCA.
If this resolves your doubt mark it as resolved.

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.