# Top View of Binary Tree

Problem Link: <https://practice.geeksforgeeks.org/problems/top-view-of-binary-tree/1>

```python
class Solution:
    
    #Function to return a list of nodes visible from the top view 
    #from left to right in Binary Tree.
    def topView(self,root):
        
        minn=float('inf')
        maxx=float('-inf')
        d={}
        q=[(root,0)]
        ans=[]
        if(root is None):
            return []
        
        while(len(q)>0):
            
            for i in range(len(q)):
                node,level=q.pop()
                minn=min(minn,level)
                maxx=max(maxx,level)
                if(level not in d):
                    d[level]=node.data
                
                if(node.left is not None):
                    q.insert(0,(node.left,level-1))
                
                if(node.right is not None):
                    q.insert(0,(node.right,level+1))
        
        for i in range(minn,maxx+1):
            ans.append(d[i])
        
        return ans
```
