The Search in a Binary Search Tree interview question asks you to find a node in a BST with a given target value and return the subtree rooted at that node. If the target is not found, return null. This leverages the BST property: all left subtree values are less than the root, and all right subtree values are greater.
Apple, Microsoft, Meta, Amazon, Google, Bloomberg, and Adobe ask this problem because it is the foundational BST operation. Every BST-based problem (insertion, deletion, validation, range search) builds on this basic search. It tests understanding of the BST invariant and recursive/iterative traversal — both of which appear throughout database indexing, ordered map implementations, and autocomplete systems.
Two clean patterns: recursive and iterative. Recursive: if root is null or root.val == target, return root. If target < root.val, recurse left. If target > root.val, recurse right. Iterative: while node is not null, compare node.val with target. Move left or right accordingly. Return the node when found, or null when the pointer goes out of bounds.
BST:
8
/ \
3 10
/ \ \
1 6 14
/ \ /
4 7 13
Search for 6:
Search for 5:
True/False instead of the subtree node — the problem asks for the subtree, not just existence.< vs >).For the Search in a Binary Search Tree coding problem, the BST interview pattern is core. Practice both recursive and iterative implementations — interviewers at Apple and Adobe sometimes ask specifically for the iterative version to avoid stack overflow on deep trees. The iterative version is O(h) time and O(1) space (no call stack), making it preferable for very deep BSTs in production settings.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Insert into a Binary Search Tree | Medium | Solve | |
| Delete Node in a BST | Medium | Solve | |
| Inorder Successor in BST II | Medium | Solve | |
| Range Sum of BST | Easy | Solve | |
| Find Mode in Binary Search Tree | Easy | Solve |