← Meta Interview Insights

Meta·Backend Engineer·Technical Phone Screen·Senior

SeniorPrefer not to say
Jun 2026

Summary

Meta backend engineer interview, got hit with a tree boundary traversal problem that looks straightforward until you actually try to implement it cleanly. The edge cases are where it gets messy.

Questions Asked (1)

Q1

Given the root of a binary tree, return the values along its boundary in anti-clockwise order starting from the root. The boundary includes the left boundary path (excluding leaves), all leaves left to right, and the right boundary path in reverse (excluding leaves and root).

Algorithms & Data Structures
Author's notes

I thought I had this one.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Break the problem into three distinct traversals: collect the left boundary (excluding leaves) top-down, collect all leaves left-to-right, then collect the right boundary (excluding leaves and root) bottom-up. Use iterative or recursive DFS with careful condition checks to avoid duplicates and handle edge cases like a single-node tree.

Pro tip: Clarify edge cases upfront—like a tree with only a root or a skewed tree—and explicitly state how you avoid adding leaves twice; this shows attention to detail and prevents bugs that interviewers at Meta often probe.

1. Clarify requirements and edge cases

Confirm the definition of boundary (left path excluding leaves, leaves left-to-right, right path reverse excluding leaves and root) and discuss edge cases like empty tree, single node, or skewed trees.

2. Design three separate traversals

Plan functions for left boundary (top-down, skip leaves), leaf collection (DFS left-to-right), and right boundary (bottom-up, skip leaves and root).

3. Implement left boundary and leaves

Write code to add left boundary nodes (excluding leaves) while traversing down, then perform a DFS to collect all leaf nodes from left to right.

4. Implement right boundary in reverse

Traverse the right boundary (excluding leaves and root) and add nodes in reverse order, either by post-order recursion or by collecting and reversing.

5. Combine and test

Concatenate the three parts, ensuring no duplicates (especially root and leaves), and walk through test cases including edge cases.

Key Points to Mention

  • Definition of boundary and exclusion of leaves from left/right paths
  • Handling of root node to avoid duplication (root is included once at start)
  • Leaf collection using DFS to ensure left-to-right order
  • Right boundary traversal in reverse order (post-order or stack)
  • Edge cases: empty tree, single node, skewed trees, and trees with only left or right children
  • Time complexity O(n) and space complexity O(h) for recursion stack

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.