FastPrepOnion-Peel Layers of a Binary Tree
Problems/Onion-Peel Layers of a Binary Tree

Onion-Peel Layers of a Binary Tree

eBay logoeBay● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report describes peeling a binary tree from the outer layer inward. In this exercise each peel removes all the current leaves from left to right. Our version is about 85% the same as that reported idea.

You are given the root of a binary tree. Imagine removing every current leaf at the same time, recording their values, and repeating until the tree is empty.

Return one array per removal round. Within each round, values must appear in the same left-to-right order produced by a postorder traversal of the original tree.

A node belongs to round 0 when it is an original leaf. Otherwise, its round is one more than the larger round of its children.

Function

findLeaves(root: TreeNode) → int[][]

Examples

Example 1

root = [1,2,3,4,5]return = [[4,5,3],[2],[1]]
root
12453

Nodes 4, 5, and 3 are removed first. Node 2 then becomes a leaf, followed by the root.

Example 2

root = [1,null,2,null,3]return = [[3],[2],[1]]
root
123

The right-skewed chain exposes one leaf per round.

Constraints

  • The tree contains between 1 and 10000 nodes.
  • -10^9 <= Node.val <= 10^9.

More eBay Onsite Interview questions

  • Extract Hashtags from a TweetONSITE INTERVIEW · Seen Nov 2026
  • Validate Ada Integer LiteralONSITE INTERVIEW · Seen Nov 2026
  • Count Distinct Pairs With Sum KONSITE INTERVIEW · Seen Nov 2026
  • Diameter of Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Count Staircases with Strictly Increasing StepsONSITE INTERVIEW · Seen Oct 2026
  • Hierarchical Permission CheckONSITE INTERVIEW · Seen Oct 2026
  • Matrix MultiplicationONSITE INTERVIEW · Seen Oct 2026
  • N-Queens Solution CountONSITE INTERVIEW · Seen Oct 2026
  • Gas StationONSITE INTERVIEW · Seen Oct 2026
  • Container With Most WaterONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • Diagonal Traversal of a Binary TreeAmazon · ONSITE INTERVIEW
  • Render an Org Chart and Find Skip-Level PairsSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
  • Find Leaves of a Binary TreeLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Delete Nodes and Return Forest RootsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Render a Task Tree from CSV RowsStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
  • Filter Undesired Comments and Their DescendantsReddit · PHONE SCREEN · ONSITE INTERVIEWReddit interview questions
  • JSON Path Lookup with Implicit Array WildcardsMongoDB · ONSITE INTERVIEWMongoDB interview questions
  • Delete and Compact a Forest SubtreePinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions
  • Match a Descendant Selector in a DOM TreeMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
All eBay interview questionsSee eBay 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[][] findLeaves(TreeNode root) {
        // Write your solution here.
    }
}
Checking account…