Tree bottom view


Can i Know what’s wrong in the code?

hello @bommareddyjyothiswaroopreddy could you please explain your logic of your code .
because you are not taking the input in the right way .
you have to construct the tree then you have to implement the logic .

I am thinking the input is given in the form of level-order traversal.Is this not correct?

i think its a level order traversal way.is it not the correct one?

no the input is given on the format of level order but you have to form the tree with the help of the queue.
if you want the proper working code please let me know i will share with you .

is it the only way?why cant i form a tree using an array.Can u show me a wrong testcase?

@bommareddyjyothiswaroopreddy try for this test case .
1 2 3 -1 4 -1 5 -1 -1 -1 6 -1 7 -1 8 -1 -1
you code’s output is different from the expected output .
try to dry run for this .
Happy Learning !!

1 Like

for given input is the tree formed this one?
pre order:1 2 4 5 3 6 7 8
in order:2 4 5 1 3 6 7 8

preorder: 1 2 4 3 5 6 7 8
inorder: 2 4 1 3 5 6 7 8

1 Like