Bottom View

Problem

Intution

If we carefully observe the above picture, we can understand that, the bottom view of binary tree is the last node in at every horizontal distance.

Perform horizontal BFS traversal and update the value of map each time at every horizontal distance

This can be acheived using map.put()

Time Complexity

O(V+E) -> Standard BFS time complexity

Space Complexity

O(K)

k-> maximum number of horizontal distances

Code

Last updated