Practice Two Sum IV - Input is a BST
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Easy#653
LeetCode ProblemTwo Sum IV - Input is a BST
Problem Statement
Given the root of a binary search tree and an integer k, return true if there exist two elements in the BST such that their sum is equal to k, or false otherwise.
Source: Two Sum IV - Input is a BST on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
root = [5,3,6,2,4,null,7], k = 9
Output
true
# Example 2
Input
root = [5,3,6,2,4,null,7], k = 28
Output
false
Constraints
The number of nodes in the tree is in the range [1, 10^4].
-10^4 <= Node.val <= 10^4
root is guaranteed to be a valid binary search tree.
-10^5 <= k <= 10^5
Related LeetCode Problems
Practice more problems similar to Two Sum IV - Input is a BST.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.