Single test case returning wrong answer

Please suggest changes to the code so as to remove the error.

check for this input

                  20
                /    \
              8       22
            /   \    /   \
          5      3 4     25
                / \      
              10    14 

For the above tree the output should be 5, 10, 4, 14, 25.

this approach is not completely correct
you also have to consider the level also

If there are multiple bottom-most nodes for a horizontal distance from root, then print the later one in level traversal. For example, in the below diagram, 3 and 4 are both the bottom-most nodes at horizontal distance 0, we need to print 4.

Reference Code

@asaurabh_26 can u please explain the helper you have writtten why pair??

pair is an inbuilt class
we can use this if we want to store two things
using int or any other data type you can store only single value
to store 2 values we can use pair

in this question i have to store root->data and level of that node both so i use pair<int,int>

pair<int ,int>pii; // it will store a pair of int and int

pii .first will give first value of pair
and pii.second will give second value of pair