FastPrepTop View of a Binary Tree
Problems/Top View of a Binary Tree

Top View of a Binary Tree

Adobe logoAdobe● MediumINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem returns what you see when you look down on a binary tree from above: the highest node in each column, from left to right. An entry for an engineering intern role in Roorkee, India (a copy of a review, August 2023, offer accepted) describes an online test and then a one-hour data structures interview about trees. Its only listed question is a changed form of the classic top-view task. The entry does not say what was changed, and it gives no limits or examples.

Our reading: since the change is unknown, this problem uses the standard top view. Our choices: columns step by one to the left and right. Within a column the highest node is seen, and among equally high nodes the leftmost on its level. Values are listed from the leftmost column. Trees have 1 to 500 nodes, with values from -10^4 to 10^4 that may repeat. The examples are new.

Because the change is unknown, our version is about 60% the same as the reported question.

You are given the root of a binary tree. Give every node a column: the root is in column 0, a left child is one column to the left of its parent (column minus 1), and a right child is one column to the right (column plus 1).

Looking at the tree from above, in each column you see only its highest node, the one closest to the root. If several nodes in a column are equally high, you see the one that comes first from left to right on that level. Return the values you see, from the leftmost column to the rightmost.

Function

topView(root: TreeNode) → List<Integer>

Examples

Example 1

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

Columns from left to right: 2 is alone in column -1; column 0 has 1 on top (4 is below it); column 1 has 3 on top (6 is below it); column 2 has 5. Answer: [2,1,3,5].

Example 2

root = [7]return = [7]
root
7

One node: [7].

Example 3

root = [10,20,30,null,40,null,null,null,50]return = [20,10,30]
root
1020405030

Node 50 is in column 1 (left, right, right from the root), but 30 is higher in that column, so 50 is hidden. 40 is hidden under 10. Answer: [20,10,30].

Constraints

  • The tree has between 1 and 500 nodes.
  • -10^4 <= node.val <= 10^4 (values may repeat)

More Adobe Phone Screen questions

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
  • Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
  • Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
  • Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
  • Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
  • Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • Insert an Employee into an Organization HierarchyWaymo · PHONE SCREENWaymo interview questions
  • Bottom View of a Binary TreeOracle · PHONE SCREEN · ONSITE INTERVIEWOracle interview questions
  • Decrypt a String from Binary Tree ColumnsBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Transform and Prune a Mode-Valued Binary TreeGoogle · PHONE SCREENGoogle interview questions
  • Team Cost Under a ManagerRippling · PHONE SCREENRippling interview questions
  • Path Between Two Binary-Tree NodesSnowflake · PHONE SCREENSnowflake interview questions
  • Count LevelsBlackRock · OABlackRock interview questions
  • Vertical Order Traversal of a Binary TreeAmazon · ONSITE INTERVIEW
  • Binary Tree Vertical Order with Stable TiesMeta · ONSITE INTERVIEWMeta interview questions
  • Top View of a Binary TreeInMobi · ONSITE INTERVIEWInMobi interview questions

Interview reports that mention this question

  • Adobe New Grad MTS Interview Questions: 7 Experiences
  • Adobe SWE Intern Interviews: 27 Experiences (Part 2 of 4)

Adobe interview experiences

  • Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
  • Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
  • Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
  • Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)
All Adobe interview questionsSee Adobe 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 List<Integer> topView(TreeNode root) {
        // Write your code here.
    }
}
Checking account…