Bottom view of a tree

def bottomView(root):
res=[]
q=[]
map_str=dict()
temp=[]
if root:
q.append([root,0])
while(q):
size = len(q)
for i in range(size):
front = q.pop(0)
x=front[1]
map_str[x]=front[0].data
if front[0].left:
q.append([front[0].left,x-1])
if front[0].right:
q.append([front[0].right,x+1])
for i in sorted(map_str):
temp.append(map_str[i])
return temp

--

--

--

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Upgrading Angular 8 to Angular 10

Angular 10

A simple Firebase solution to enable location based authentication in your web application

React Custom Hooks: Creating A Reusable Meme Generator

A complete <dev> guide for better buttons

An Introduction to Map in JavaScript for Beginners

How to Use React Context to Manage State in Your App.

How to generate an HTML table and a PDF with Node & Google Puppeteer

Simple guide to start with NodeJs,Express and MongoDB

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dhanarajappu

Dhanarajappu

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.

More from Medium

best the Buy custom twitter comments

CS 373 Spring 2022: Saran Chockan Blog # 14

CS373 Spring 2022: Jay Acosta — Week 10

How got 90+ GTMetrix grade with minimum cost?