Answer: ServiceNow OA Question 2024 May | Trees | on-campus
Answer · Posted Jun 2026
Solution: Lowest Common Ancestor — Recursive Depth First Search Approach We can solve this problem recursively by traversing the binary tree. For any node, we search for p and q in its left and right subtrees: If the current node is null, or if it is equal to either p or q, we return the current node directly. We recursively search in the left subtree and the right subtree. If both left and right recursive searches return a non-null node, ...
The full answer & interview discussion are available to premium members.
Log in Create a free account