Can anyone explain how the input has to be interpreted


#1

I am not able to understand the notation of tree used in the input. Can someone please explain?


#2

TreeNode is a struct or node of a tree having 3 members 1 being the value and other 2 being the pointer of same type i.e. TreeNode, left child and right child. In C++ you will access value of a node A, its left child and right child as A->val, A->left and A->right respectively, where A is pointer. The pointer passed in the function as A is the pointer to the Root node.


#3

My query was the format of input given. For example- 7 10 9 20 -1 -1 -1 -1
Here how do we interpret child nodes?


#5

7 10 9 20 -1 -1 -1 -1, as a test case will result in a BST as…

       10
     /    \
   9      20 
 /   \  /    \

NULL NULL NULL NULL

in input null node is basically a -1.
First No. (7 here) is the number of nodes to follow.