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. The two elements must be distinct nodes in the tree.[1][3]
Input/Output Examples
Example 1: Input: root = [5,3,6,2,4,null,7], k = 9 → Output: true (since 4 + 5 = 9 or 2 + 7 = 9).[3][7][1]
Example 2: Input: root = [5,3,6,2,4,null,7], k = 28 → Output: false (no pair sums to 28).[7][1][3]
Constraints
The number of nodes in the tree is in the range [1, 10^4].[3]
-10^4 <= Node.val <= 10^4.[3]
root is guaranteed to be a valid binary search tree.[3]