Tree Top View problem

what’s wrong with my code

hi, your code is giving wrong output for 1 2 -1 3 -1 -1 -1.