Doubt in top view of binary tree

the approach is similar to vertical order traverval
where in map
key–>
horizontal distance
value–>pair<int,int> (root->data,level}
so we have update the map when we see new horizontal distance or when the level of the current node is less than the level seen for sofar in the map for the same horizontal distance right?

void topView1(node *root, int level, int dist, map<int, pair<int, int> > &mp) {
    if(root == NULL) {
        return;
    }
    if(mp.find(dist) == mp.end() or level<mp[dist].second) {//this should be like this level>mp[dist].second  right?
        mp[dist] = {root->data, level};
    }
    topView1(root->left, level+1, dist-1, mp);
    topView1(root->right, level+1, dist+1, mp);
}
void topView(node *root)
{
   map<int, pair<int, int> >mp;
   topView1(root, 0, 0, mp);
   for(auto val:mp){
       cout<<val.second.first<<" ";
   }

ohh what i am asking sorry stupid ,okay it should like this only

Yes , You are right that it’s similar to vertical order traversal.

hi if we change m[dist].second<level
it will bottom view cause
we have to update the map when we see a new horizontal distance or current level of the node is greter than the level seen sofar in the hash map right?

Yes, you are right that whenever you will find m[dist].second<level you have to update it as there will be another level of that binary tree.
It’s like you are on level 2 and you found that m[dist].second<level so there will be level 3 also and for that we will update our map too.

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.