Vertical Order Traversal of Binary Tree

My code is showing correct output for the given test case but showing run error after submitting for test case 1. Please help with this.

hey @anshika_agrawal_5501
for test case like
1 1125212117 -1 -1 -1
your code gives error
take further input when the value is not -1
While traversing the tree, we can recursively calculate HDs. We initially pass the horizontal distance as 0 for root. For left subtree, we pass the Horizontal Distance as Horizontal distance of root minus 1. For right subtree, we pass the Horizontal Distance as Horizontal Distance of root plus 1. For every HD value, we maintain a list of nodes in a hash map. Whenever we see a node in traversal, we go to the hash map entry and add the node to the hash map using HD as a key in map.
you can see this