Bottom view of binary tree one test case fail


can you tell me my logic is correct or not one test case fail in tree bottom view printing please update my code with comment

@bishtmanish786 Consider the case:
20 8 22 5 3 4 25 -1 -1 10 14 -1 -1 -1 -1 -1 -1 -1 -1

Expected Output:
5 10 4 14 25

Your Output:
5 10 4 22 25

With this example, check how you are going wrong with the code or logic.

Or follow this approach:

By maintaining a hashmap for horizontal distance of each node and by the BFS traversal you can solve this problem.

Hope this helps! :slightly_smiling_face:

@pratyush63 sir

update ->
i have done this problem https://ide.codingblocks.com/s/119779 is it right way to solve it ?

@bishtmanish786 yes it is right way. :+1:

1 Like