Challenge - 5 Problems
Bottom View Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Bottom View for a Simple Binary Tree
What is the output of the bottom view traversal for the given binary tree?
DSA Java
class Node { int data; Node left, right; Node(int data) { this.data = data; left = right = null; } } // Tree structure: // 20 // / \ // 8 22 // / \ \ // 5 3 25 // / \ // 10 14 // Bottom view expected output: 5 10 3 14 25 public class BottomView { public static void main(String[] args) { Node root = new Node(20); root.left = new Node(8); root.right = new Node(22); root.left.left = new Node(5); root.left.right = new Node(3); root.right.right = new Node(25); root.left.right.left = new Node(10); root.left.right.right = new Node(14); // Assume bottomView(root) returns a list of integers representing bottom view System.out.println(bottomView(root)); } // Dummy method for illustration static java.util.List<Integer> bottomView(Node root) { return java.util.Arrays.asList(5, 10, 3, 14, 25); } }
Attempts:
2 left
💡 Hint
Bottom view shows the last node visible at each horizontal distance from the root.
✗ Incorrect
The bottom view includes nodes visible when the tree is viewed from the bottom. Nodes 5, 10, 3, 14, and 25 are the bottom-most nodes at their horizontal distances.
❓ Predict Output
intermediateBottom View Output for a Left-Skewed Tree
What will be the bottom view output for this left-skewed binary tree?
DSA Java
class Node { int data; Node left, right; Node(int data) { this.data = data; left = right = null; } } // Tree structure: // 1 // / // 2 // / //3 // Bottom view expected output: 3 public class BottomView { public static void main(String[] args) { Node root = new Node(1); root.left = new Node(2); root.left.left = new Node(3); System.out.println(bottomView(root)); } static java.util.List<Integer> bottomView(Node root) { return java.util.Arrays.asList(3); } }
Attempts:
2 left
💡 Hint
In a left-skewed tree, bottom view shows the lowest node at the leftmost horizontal distance.
✗ Incorrect
All nodes share the same horizontal distance, but the bottom view shows the lowest node, which is 3.
🔧 Debug
advancedIdentify the Error in Bottom View Implementation
What error will this code produce when trying to compute the bottom view of a binary tree?
DSA Java
import java.util.*; class Node { int data; Node left, right; Node(int data) { this.data = data; } } public class BottomView { public static void bottomView(Node root) { Map<Integer, Integer> map = new HashMap<>(); Queue<Node> queue = new LinkedList<>(); Queue<Integer> hdQueue = new LinkedList<>(); queue.add(root); hdQueue.add(0); while (!queue.isEmpty()) { Node temp = queue.poll(); int hd = hdQueue.poll(); map.put(hd, temp.data); if (temp.left != null) { queue.add(temp.left); hdQueue.add(hd - 1); } if (temp.right != null) { queue.add(temp.right); hdQueue.add(hd + 1); } } for (int key : map.keySet()) { System.out.print(map.get(key) + " "); } } }
Attempts:
2 left
💡 Hint
HashMap does not guarantee order of keys when iterated.
✗ Incorrect
The code runs without error but prints bottom view nodes in arbitrary order because HashMap keys are unordered. Using TreeMap or sorting keys fixes this.
❓ Predict Output
advancedBottom View Output for Tree with Overlapping Horizontal Distances
What is the bottom view output for this binary tree with overlapping horizontal distances?
DSA Java
class Node { int data; Node left, right; Node(int data) { this.data = data; left = right = null; } } // Tree structure: // 1 // / \ // 2 3 // \ \ // 4 5 // \ \ // 6 7 // Bottom view expected output: 2 4 6 7 public class BottomView { public static void main(String[] args) { Node root = new Node(1); root.left = new Node(2); root.right = new Node(3); root.left.right = new Node(4); root.right.right = new Node(5); root.left.right.right = new Node(6); root.right.right.right = new Node(7); System.out.println(bottomView(root)); } static java.util.List<Integer> bottomView(Node root) { return java.util.Arrays.asList(2, 4, 6, 7); } }
Attempts:
2 left
💡 Hint
Bottom view shows the last node visible at each horizontal distance from the root.
✗ Incorrect
Nodes 2, 4, 6, and 7 are the bottom-most nodes at their horizontal distances, so they appear in the bottom view.
🧠 Conceptual
expertHorizontal Distance Concept in Bottom View
Which statement best describes the role of horizontal distance (HD) in computing the bottom view of a binary tree?
Attempts:
2 left
💡 Hint
Think about how nodes align horizontally when viewed from the bottom.
✗ Incorrect
Horizontal distance groups nodes vertically; bottom view shows the last node encountered at each horizontal distance during level order traversal.
