Top view tree 1 test case not working

question link https://hack.codingblocks.com/contests/c/917/954
answer https://ide.codingblocks.com/s/114238

Hello @nimishkhattar07,

  1. Your code is giving run-time error for the input test cases like:
    1 2 3 -1 4 5-1 6 -1 -1 7 8 -1 -1 9 -1 -1 -1 -1
    Tree Formed:
    _____________1
    ______2_____________3
    ____________4,5
    ______6_____________7
    8________________________9
    Here:
    1,4 and 5 lies on same vertical axis. Thus, only 1 will be printed.
    2 and 6 on same. 2 will be printed
    3 and 7 is same. 3 will be printed.
    Expected Output:
    8 2 1 3 9
    Your Output:
    Run-time error

  2. It is printing the bottom view instead of the top view.
    Example 1:
    1 2 3 4 5 6 7 -1 -1 -1 -1 -1 -1 -1 -1
    Expected Output:
    4 2 1 3 7
    Your Output:
    4 2 6 3 7

    Example 2;
    1 2 3 4 5 6 -1 -1 -1 -1 -1 -1 -1
    Expected Output:
    4 2 1 3
    Your Output:
    4 2 6 3

Hope, this would help.
Give a like, if you are satisfied.

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.