To solve this problem, you'll have to open it on the computer

Two Sum IV - Input in a BST

Tree
easy
Score: 20

Given the root of a Binary Search Tree and a target number k return 1 if there exist two elements in the BST such that their sum is equal to the given target else return 0.

Class TreeNode:
    val (int)
    left (TreeNode)
    right (TreeNode)

Input Format:

First Parameter - TreeNode root

Second Parameter - number k

Output Format:

Return the number.

Example 1:

img

Input:
    root = [11 7 14 3 9]
    k = 17
Output:
    1

Example 2:

img

Input:
    root = [11 7 14 3 9]
    k = 200
Output:
    0

Constraints:

  • The number of nodes is in the range [1,104]
  • -104 <= node.val <= 104.
  • root is guaranteed to be a valid binary search tree.
  • -105 <= k <= 105
  • Expected Time Complexity: O(N).
  • Expected Space Complexity: O(logN).
Submit code to see the your result here