sol: https://ide.codingblocks.com/s/417810
prob: https://hack.codingblocks.com/app/contests/2022/80/problem
raising some error related to stoi
sol: https://ide.codingblocks.com/s/417810
prob: https://hack.codingblocks.com/app/contests/2022/80/problem
raising some error related to stoi
@raghav007 you are not forming the three in the correct manner for this type of input.
you can do this in the way you can form the tree i.e if there is true value then you will attach the data value to the corresponding side otherwise if it is fase then you will attach null value.
try to go in this way:
in this you can make the build function in which you will give two conditions one for when the string is true and the other for false when the it has no child.
when it has no child you will simple attach null to it but when it has child then you will form the node for the data value and then you will check for the child strings of and then pass them to attach at the left and right following the same criteria mentioned above.
Here for your reference i am attaching the code:
if you have any doubt you can ask here:
Happy Learning!!
I made the changes there is an error somewhere else too
@raghav007 yes your buildtree function is correct now but what is the logic that you are using in your levelorder?
is that logic is same as in the editorial of the course or you are using yourlogic?
please elaborate here.
my logic was the one that was described in the video for this problem, your logic seems simpler please explain how you are doing it without adding null for each level
@raghav007 in my logic for the present length i am just adding all the child nodes in the new vector former for every level and after that i am printing them accordingly from start to end and end to start.
the working of the for loop is that if i new the present length of the queue tells about the nodes in the level and to form the next level we are adding all the child nodes of the nodes of the present level.
if you still have any doubt please let me know.
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.