We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def topView(root):
Q=deque([])
top_view={}
Q.append((root,0))
while Q:
node,h = Q.popleft()
if not node:
continue
if h not in top_view:
top_view[h]=node
Q.append((node.left,h-1))
Q.append((node.right,h+1))
for some reason they don't let me post the bottom half, anyway sort top_view by key and print the values
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Tree : Top View
You are viewing a single comment's thread. Return to all comments →
for some reason they don't let me post the bottom half, anyway sort top_view by key and print the values