FastPrepBoundary of a Binary Tree, Anticlockwise
Problems/Boundary of a Binary Tree, Anticlockwise

Boundary of a Binary Tree, Anticlockwise

Adobe logoAdobe● MediumFULLTIMEINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem returns the values around the outside of a binary tree, going anticlockwise from the root. The order is: the root, the nodes down the left side, the leaves from left to right, and the nodes back up the right side, with no node listed twice. Three Adobe reports point to it, each from the opening technical interview. An MTS-1 report from an off-campus drive (posted July 2022) spells out this order and says the interviewer wanted it done in a single pass over the tree. A product engineer entry (a copy of a review, August 2024) gives only the name of this traversal. An SDE intern report (posted August 2024) mentions printing a tree in anticlockwise order, which it calls a hard question. We read that as the same boundary order, since the post does not define it further.

Our choices: the values are returned as a list instead of printed. When a node on the left side has no left child, the side continues through its right child, and the mirror rule applies on the right side. A one-node tree gives just the root. Trees have 1 to 2000 nodes, with values from -1000 to 1000. The examples are new.

Our version is about 85% the same as the reported questions.

Given the root of a binary tree, return the values on its boundary, read anticlockwise starting at the root. The boundary is made of these parts, in this order:

  1. The root.
  2. The left edge, top to bottom: start at the root's left child; from each node move to its left child, or to its right child if it has no left child. Stop before reaching a leaf. If the root has no left child, the left edge is empty.
  3. The leaves (nodes with no children), from left to right. The root is not counted here.
  4. The right edge, bottom to top: built like the left edge but starting at the root's right child and preferring right children, again stopping before a leaf, then listed in reverse.

Each node appears once. A tree with a single node has the boundary [root.val]. Values may repeat; list each node's value.

Function

boundaryTraversal(root: TreeNode) → List<Integer>

Examples

Example 1

root = [6,2,9,1,4,null,11,null,null,3,5,10]return = [6,2,1,3,5,10,11,9]
root
62143591110

Root 6. The left edge is just 2, because its left child 1 is a leaf. The leaves from left to right are 1, 3, 5, 10. The right edge from the top is 9, 11 (10 is a leaf), so going up it is 11, 9.

Example 2

root = [7,null,3,8,null,2,6]return = [7,2,6,8,3]
root
73826

The root has no left child, so the left edge is empty. The leaves are 2, 6. The right edge starts at 3; 3 has no right child, so the edge goes to its left child 8, and stops above the leaves. Going up, that edge is 8, 3.

Example 3

root = [4]return = [4]
root
4

A single node is the whole boundary: the root, listed once.

Constraints

  • The tree has between 1 and 2000 nodes.
  • -1000 <= node.val <= 1000
  • The tree does not have to be balanced. It can be a single chain of 2000 nodes.

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

  • N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • House Robber IIIOkta · PHONE SCREENOkta interview questions
  • Render a Task Tree from CSV RowsStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
  • Validate Binary Search TreeKotak Mahindra Bank · PHONE SCREENKotak Mahindra Bank interview questions
  • House Robber IIIGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Binary Tree Target-Sum PathsByteDance · PHONE SCREENByteDance interview questions
  • House Robber IIIVisa · PHONE SCREENVisa interview questions
  • Find All Paths for a Name in a File SystemThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
  • Validate a BST with a Custom ComparisonApple · PHONE SCREENApple interview questions
  • Filter Undesired Comments and Their DescendantsReddit · PHONE SCREEN · ONSITE INTERVIEWReddit interview questions

Interview reports that mention this question

  • Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
  • Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
  • Adobe New Grad MTS Interview Questions: 7 Experiences
  • Adobe SWE Intern Interviews: 27 Experiences (Part 2 of 4)
  • Adobe Intern Interview Questions: 54 Experiences (Part 1 of 4)

Adobe interview experiences

  • Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
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> boundaryTraversal(TreeNode root) {
        // Write your code here.
    }
}
Checking account…