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.
Example 1
Input: root = [5,3,6,2,4,null,7], k = 9
Output: true
Explanation: The tree contains 4 and 5, and 4 + 5 = 9.
Example 2
Input: root = [5,3,6,2,4,null,7], k = 28
Output: false
Explanation: The two largest values are 6 and 7, and 6 + 7 = 13 is far below 28, so no pair can reach it.
Example 3
Input: root = [2,1,3], k = 4
Output: true
Explanation: 1 + 3 = 4, and both values are in the tree.
Traverse the tree keeping a set of values seen. For each node, if its complement k - value is already in the set, a pair exists.
Run checks all cases above. Submit evaluates all test cases.