Problem
You get the root of a binary search tree and an integer val. The input shows the tree as a list in level order. This order lists the nodes one level at a time, from left to right. A null value marks a missing child.
In a binary search tree, the value of each node is larger than all values in its left subtree. It is smaller than all values in its right subtree. The subtree of a node is that node and all nodes below it.
Find the node whose value is val, and return the subtree of that node. If no node has the value val, return null. The output shows an empty tree as [].
Example 1
- Input:
- root = [8,3,12,1,5,10,14], val = 3
- Output:
- [3,1,5]
- Explanation:
- Node 3 has the children 1 and 5, so its subtree has three nodes.
Example 2
- Input:
- root = [8,3,12,1,5,10,14], val = 7
- Output:
- []
- Explanation:
- No node has the value 7.
Example 3
- Input:
- root = [20,null,30,25], val = 30
- Output:
- [30,25]
Constraints
- 1 <= number of nodes <= 5000
- 1 <= Node.val <= 10^7
- root is a binary search tree.
- 1 <= val <= 10^7
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Balance a Binary Search Tree
Coding
- Binary Search Tree Iterator
Coding
- Binary Search Tree Iterator II
Coding
- Binary Search Tree to Greater Sum Tree
Coding · Binary Search Tree · Binary Tree · Depth-First Search
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 700. Search in a Binary Search Tree
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source