image.png


class Solution {
  public:
    vector<int> bottomView(Node *root) {
        
        vector<int > res;
        
        if(!root) return res;
        
        queue <pair <Node* , int>> q;
        
        map<int , int > mpp;
        
        q.push({root , 0});
        
        
        while(!q.empty()){
            auto it  = q.front();
            q.pop();
            
            Node* node = it.first;
            int line = it.second;
            
            mpp[line] =  node->data;
            
            if(node->left != NULL){
                q.push({node->left , line-1});
            }
            
            if(node->right != NULL){
                q.push({node->right , line+1});
            }
            
        }
        
        for(auto it : mpp){
            res.push_back(it.second);
        }
        
        return res;
    }
};

https://www.geeksforgeeks.org/problems/bottom-view-of-binary-tree/1

https://takeuforward.org/data-structure/bottom-view-of-a-binary-tree/