Easy

Quiz

#653 Two Sum IV - Input is a BST

APPROACH

Given the root of a binary search tree and a target integer k, determine whether any two distinct nodes in the BST sum to k. Return true if such a pair exists, false otherwise.

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
1 of 4
1:00

What is the optimal approach for this problem?