Tap here to switch tabs
Problem
Submissions

Problem: Two Sum BSTs

Try to solve the Two Sum BSTs problem.

Statement

Given the roots of two binary search trees root1 and root2, alongside an integer target, return true if there exists a node in the first tree with value val1 and a node in the second tree with value val2 such that val1 ++ val2 equals target. Otherwise, return false.

Constraints:

  • The number of nodes in each tree is in the range [1,5000][1, 5000].

  • −109≤-10^9 \leq Node.val, target ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Two Sum BSTs

Try to solve the Two Sum BSTs problem.

Statement

Given the roots of two binary search trees root1 and root2, alongside an integer target, return true if there exists a node in the first tree with value val1 and a node in the second tree with value val2 such that val1 ++ val2 equals target. Otherwise, return false.

Constraints:

  • The number of nodes in each tree is in the range [1,5000][1, 5000].

  • −109≤-10^9 \leq Node.val, target ≤109\leq 10^9