1)tree is giving error given input 1 2 3 4 5 -1 -1.
- Sample Input seems to be wrong with explanation.
1)tree is giving error given input 1 2 3 4 5 -1 -1.
@RULEREMPIRES You have to make tree from level order traversal, its the level order input given to you. Those -1s have a significance, so that you can create a unique tree.
Here 1 is root, 2,3 it childs, then 4, 5 childs of 2.
Then for 3 left child is null or no child that -1 signifies. then it has right child as 6. all other -1 shows that 4, 5, 6 are leaf node.
Refer the diagram in right view question!
two testcases failing.
@RULEREMPIRES lets take a test case.
1 6 2 8 7 4 3 11 -1 9 -1 5 -1 -1 -1 -1 -1 10 -1 -1 -1 -1 -1
Your output :- 1 6 8 11
correct :- 1 6 8 11 10
Draw a tree and dry run it you will be good to go!