Construct balanced tree

given the level order input, we have to construct balanced trree

input : 1 2 3 4 5 6 -1 -1 -1 -1 -1 -1 -1

Hi @animeee_13
To construct a balanced tree what do is that take input one by one and then first make first element as root node and then take next element as left child of root if it is not -1 and then take right next element as right child. You have to take element and starting from left you have to make then nodes if they are not -1.

what will be my terminating condition?

See when you get -1 as a child for a node then you dont make any children of that node so when all the nodes have only -1 as data for their children then you will terminate taking inputs.

I understand what are you saying, the point is that i dont know the input size.
Can you give a favour, please provide me the code so that i can understand clearly.

Thank you soo much for the code …!!!
:grinning:

1 Like

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.