Tap here to switch tabs
Problem
Submissions

Problem: Two Sum BSTs

Two Sum BSTs asks whether one node from each of two binary search trees has values that add up to a given target, returning true or false.

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

Two Sum BSTs asks whether one node from each of two binary search trees has values that add up to a given target, returning true or false.

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