The problem. Given the root of a binary search tree and a number k, return true if two different nodes in the tree add up to k.
root = [5, 3, 6, 2, 4, null, 7], k = 9 -> true (2 + 7, or 3 + 6, or 4 + 5)
root = [5, 3, 6, 2, 4, null, 7], k = 28 -> false
root = [1], k = 2 -> false (the same node can't be used twice)Members only · free account
The rest of this lesson, with 6 more sections, 1 drawing, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson