FastPrepBottom View of a Binary Tree
Problems/Bottom View of a Binary Tree

Bottom View of a Binary Tree

Oracle logoOracle● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Oracle onsite interview. The report asks for the approach to the bottom view of a binary tree. It does not say what the view is, what to do when two nodes land in the same spot, the traversal order, the function signature, the test data, or the input limits. We kept the tree-view task and added the usual rules. Our version is about 86% the same as the reported question.

You are given the root of a binary tree. Assign horizontal distance 0 to the root, distance d - 1 to the left child of a node at distance d, and distance d + 1 to its right child.

The bottom view contains one value for every horizontal distance: choose the node with the greatest depth at that distance. If two nodes at the same distance also have the same depth, choose the node visited later by a left-to-right level-order traversal. Return the selected values from the smallest horizontal distance to the largest.

Return an empty array when root is null.

Function

bottomView(root: TreeNode) → int[]

Examples

Example 1

root = [20,8,22,5,3,null,25,null,null,10,14]return = [5,10,3,14,25]
root
2085310142225

The visible nodes from left to right are 5, 10, 3, 14, and 25.

Example 2

root = [1,2,3,null,4,5,null]return = [2,5,3]
root
12435

Nodes 4 and 5 share horizontal distance 0 and depth 2. Node 5 is visited later in left-to-right level order, so it wins the tie.

Example 3

root = []return = []
root
empty

An empty tree has no horizontal distances in its bottom view.

Constraints

  • The tree contains between 0 and 10000 nodes.
  • -1000000000 <= Node.val <= 1000000000
  • The input uses a level-order array where null denotes a missing child.

More Oracle Onsite Interview questions

  • Course ScheduleONSITE INTERVIEW · Seen Nov 2026
  • Shortest Subarray with Sum at Least KONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Minimum Meeting RoomsONSITE INTERVIEW · Seen Nov 2026
  • Shortest Window with Required CountsONSITE INTERVIEW · Seen Nov 2026
  • Maximum Subarray Sum with One DeletionONSITE INTERVIEW · Seen Nov 2026
  • Shortest Deletion for Distinct CharactersONSITE INTERVIEW · Seen Nov 2026
  • Count Dropped Rate-Limited RequestsONSITE INTERVIEW · Seen Nov 2026
  • Design Authentication ManagerONSITE INTERVIEW · Seen Oct 2026
  • Maximum Bouquet ValueONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Delete Nodes and Return Forest RootsGoogle · ONSITE INTERVIEW
  • Group Identical Tree LevelsSalesforce · ONSITE INTERVIEW
  • Insert an Employee into an Organization HierarchyWaymo · PHONE SCREEN
  • Vertical Order Traversal of a Binary TreeAmazon · ONSITE INTERVIEW
  • Decrypt a String from Binary Tree ColumnsBloomberg LP · PHONE SCREEN
  • Binary Tree Vertical Order with Stable TiesMeta · ONSITE INTERVIEW
  • Everyone Under a ManagerAdobe · PHONE SCREEN
  • Team Cost Under a ManagerRippling · PHONE SCREEN
  • Top View of a Binary TreeInMobi · ONSITE INTERVIEW
  • Path Between Two Binary-Tree NodesSnowflake · PHONE SCREEN
See Oracle hiring insights
Saved
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public int[] bottomView(TreeNode root) {
      // write your code here
    }

}
Checking account…