Tree left view - python

Hi Team, i have created the code for the left view of the tree, could you please help and check what is wrong with the code as it is not passing all the test cases.

Thanks

hello @mridulpant

the approach that u r using to construct tree will worl only for complete tree , for other type of tyep it will construct wrong structure.
correct it.

can you help me in correcting the code while constructing the tree

to construct a tree from level order , we perform level order traversal only .
look at this code.

this code is exaclty similar to level order traversal.
we pop node from q.
now we check whether its left node exist or not by checking value of c1 . it exist we create a new node and add it to the left of current node. and push that newly created node in q.

similarly we do for right node.
and at end when q get empty .
the tree construction is done and we return root of the tree

thanks a lot, i got the answer… awesome

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.