Advertisement
Rohit4Pal

Untitled

Apr 23rd, 2022
1,064
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. void bottomViewBT(Node *root,map<int,map<int,vector<int>>> &mp,int hdis,int vdis){
  2.  
  3.     //base
  4.     if(root==NULL)
  5.         return ;
  6.  
  7.     mp[hdis][vdis].push_back(root->data);
  8.     bottomViewBT(root->left,mp,hdis-1,vdis+1);
  9.     bottomViewBT(root->right,mp,hdis+1,vdis+1);
  10. }
  11. vector<int> bottomView(Node* root) {
  12.  
  13.     map<int,map<int,vector<int>>> mp;
  14.     bottomViewBT(root,mp,0,0);
  15.  
  16.     vector<int> res;
  17.     for(auto i:mp){
  18.  
  19.         map<int,vector<int>> p=i.second;
  20.  
  21.         for(auto q=p.rbegin();q!=p.rend();q++) {
  22.             vector<int> temp = q->second;
  23.             res.push_back(temp[0]);
  24.             break;
  25.         }
  26.     }
  27.  
  28.     return res;
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement