Practice Closest Nodes Queries in a Binary Search Tree
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Closest Nodes Queries in a Binary Search Tree
Problem Statement
Given the root of a binary search tree and queries, for each query value, return [floor,ceiling] from the values in root: floor is the largest tree value no greater than the query, and ceiling is the smallest no less than it. Use -1 separately for either missing bound. Return pairs in query order.
Source: Closest Nodes Queries in a Binary Search Tree on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
root = [6,2,13,1,4,9,15,null,null,null,null,null,null,14], queries = [2,5,16]
[[2,2],[4,6],[15,-1]]
# Example 2
root = [4,null,9], queries = [3]
[[-1,4]]
Constraints
Related LeetCode Problems
Practice more problems similar to Closest Nodes Queries in a Binary Search Tree.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.