Bottom View of Binary Tree
Medium Problems DSA practice problem on Onlearn.
Difficulty: medium.
Topics: Bottom View of a Binary Tree, Binary Tree, Traversal, Breadth-First Search, Queue, Map, Time Complexity, Space Complexity, Big O Notation, Data Structures, Algorithm, queue, binary tree, hash map, bfs, tree traversal, Vertical Order Traversal, Tree Traversal (BFS).
Problem Statement: Given the root of a Binary Tree, return its Bottom View. The Bottom View of a Binary Tree is the set of nodes visible when we see the tree from the bottom. If multiple nodes lie on the same vertical line, the lowest node on that vertical line is considered. The nodes should be returned in order from the leftmost vertical line to the rightmost vertical line. Input Format: The input represents a binary tree where nodes are provided in a level order traversal. A value of 1 indicates a null child. Output Format: Return a list of integers representing the nodes in the bottom view, ordered from left to right based on their vertical position. Example 1: Input: (This represents the tree: 1 / \ 2 3 / \ / \ 4 10 9 11 / 5 \ 6 ) Output: Explanation: The bottom view of the binary tree would comprise of the nodes that are the last encountered nodes for each vertical index. For vertical index 2, node 4 is seen. For 1, node 5 is seen. For 0, node 6 is seen (it's below 1, 2). For 1, node 3 is seen (it's below 1, 9). For 2, node 11 is seen (it's below 1, 3). Example 2: Input: Output: Explanation: This output corresponds to the bottom view from left to right vertical lines.