Answer: Walmart OA Question 2024 April | Trees | on-campus
Answer · Posted Jun 2026
Solution: Lowest Common Ancestor — BST Iterative Search Approach We can solve this problem in O(H) time (where H is the tree height) and O(1) space by utilizing the core property of a **Binary Search Tree (BST)**: for any node, all values in its left subtree are smaller, and all values in its right subtree are larger. Starting from the root, we compare the values of p and q with the current node: If both p and q have values ...
The full answer & interview discussion are available to premium members.
Log in Create a free account