Input is not clear

how exactly we will take input in this question?

hello @nikhilthechamp871

true indicates that subtree exist
false indicates that substree doesnt exist

image

first read root node.
then check whether left subtree exist or not by reading a string .
if it is true that means left subtree exist ,so build left tree recursively
otherwise assign NULL to left of current node.

again read one more string to check whether right subtree exist or not.
if it exist(string is true) then build it recursively
otherwise
assign NULL to right of current node

and at the end return current node

do we have to write a function that will build a tree for us through input??

yes …
…
…
…

can u show me how the tree will look which is given in the testcase.

10 true 20 true 40 false false true 50 false false true 30 true 60 false false true 73 false false

                 10
              /           \
            20             30
       /         \         /    \
   40           50       60        73
```

I have written this build function check it
it is giving segmentation fault

make ur node constructor like this


    node(int d){
        data=d;
        left=NULL;

        right=NULL;
    }

oh it worked now i forgot to add these.

btw is the correct for building tree from given input?

…

yes…

thanks @aman212yadav
the code worked for me.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.