1 minute read

You are given two binary search trees a and b and an integer target. Return whether there’s a number in a and a number in b such that their sum equals to target

Constraints

  • n ≤ 100,000 where n is the number of nodes in a
  • m ≤ 100,000 where m is the number of nodes in b

https://binarysearch.com/problems/Sum-of-Two-Numbers-in-BSTs

Examples

Example 1

Input

  • a =
  • b =
  • target = 9

Output

  • answer = True

Explanation

We can pick 7 from a and 2 from b.

Example 2

Input

  • a =
  • b =
  • target = 4

Output

  • answer = False

Solution

Leave a comment