← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Senior

SeniorPrefer not to say
May 2026

Summary

Meta SWE interview with two back-to-back tree problems on a BST. Both questions had meaningful follow-ups baked in, so it wasn't just 'code this' but also 'explain your choices and complexity.' Felt like a solid technical screen.

Questions Asked (2)

Q1

Given the root of a BST, implement vertical order traversal. Assign column 0 to the root, -1 to left children, +1 to right children. Return node values column by column left to right, top to bottom within each column, with ties broken by left-to-right position at the same depth. Walk through your algorithm, the data structures you'd use, and the time/space complexity.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I went with a BFS approach, tracking (node, col, depth) tuples and dumping everything into a map from column to list of (depth, value) pairs.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the tie-breaking rule and confirming the definition of vertical order. Then, describe a BFS approach using a queue and a map from column to list of values, processing nodes level by level to ensure top-to-bottom and left-to-right ordering. Finally, analyze time and space complexity and discuss potential optimizations.

Pro tip: Mention that using BFS naturally handles the tie-breaking rule because nodes at the same depth are processed left-to-right, and within the same column, their order is preserved. Also, note that a DFS approach would require sorting by depth and horizontal position, which adds complexity.

1. Clarify the problem

Restate the problem in your own words, confirm the tie-breaking rule (top-to-bottom, left-to-right within same depth and column), and ask about edge cases (e.g., empty tree, single node).

2. Choose the algorithm

Decide between BFS and DFS. BFS is preferred because it processes nodes level by level, naturally satisfying the top-to-bottom and left-to-right ordering within each column.

3. Outline data structures

Use a queue for BFS, storing nodes along with their column indices. Use a hash map (or dictionary) to group node values by column, and keep track of the minimum and maximum column indices to output columns in order.

4. Walk through the algorithm

Initialize the queue with the root at column 0. While the queue is not empty, dequeue a node, add its value to the map under its column, and enqueue its left child with column-1 and right child with column+1. After BFS, iterate columns from min to max and output the lists.

5. Analyze complexity

Time complexity is O(n) because each node is visited once. Space complexity is O(n) for the queue and the map. Mention that the map's lists preserve insertion order, which matches the required ordering.

Key Points to Mention

  • BFS ensures top-to-bottom and left-to-right ordering within each column.
  • Use a hash map to group values by column, and track min/max columns for output.
  • Time complexity: O(n) where n is the number of nodes.
  • Space complexity: O(n) for the queue and map.
  • Edge cases: empty tree, skewed tree, and nodes with same column but different depths.
  • Alternative DFS approach would require sorting by depth and horizontal position, increasing complexity.

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

Q2

Convert a BST into a sorted non-circular doubly linked list in-place, reusing the existing nodes so that each node's left pointer becomes its prev and right pointer becomes its next. Return the head of the list. Compare recursive and iterative approaches, discuss edge cases like empty trees, single nodes, and skewed trees, and analyze time and space complexity.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is basically an in-order traversal where you're stitching nodes together as you go.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and edge cases, then present an in-order traversal approach that rewires pointers in-place. Compare recursive and iterative implementations, discussing trade-offs in time/space and handling of skewed trees.

Pro tip: Emphasize that the transformation must be in-place and that the resulting list should be non-circular; explicitly set the head's prev and tail's next to null to avoid cycles.

1. Clarify requirements and edge cases

Confirm that the list should be sorted (in-order), non-circular, and in-place. Discuss edge cases: empty tree, single node, skewed tree (all left or all right).

2. Choose traversal strategy

Decide between recursive and iterative in-order traversal. Recursive is simpler but uses O(h) stack space; iterative uses explicit stack, also O(h) space, but can be more robust for deep trees.

3. Implement pointer rewiring

During traversal, maintain a prev pointer. For each node, set node.left = prev, and if prev exists, prev.right = node. Update prev to current node.

4. Handle head and tail

The first node visited becomes the head; set its left to null. After traversal, set the last node's right to null to ensure non-circularity.

5. Analyze complexity and trade-offs

Time: O(n) for both approaches. Space: O(h) for recursion/stack, where h is tree height; worst-case O(n) for skewed trees. Discuss iterative vs recursive readability and stack overflow risk.

Key Points to Mention

  • In-order traversal yields sorted order for BST.
  • In-place transformation reuses nodes without extra allocation.
  • Recursive approach: simple but O(h) stack space; risk of stack overflow for skewed trees.
  • Iterative approach: explicit stack, O(h) space, avoids recursion depth limits.
  • Edge cases: empty tree returns null; single node becomes head with null prev/next; skewed tree degenerates to O(n) space.
  • Time complexity O(n), space complexity O(h) for both, but iterative can be O(1) if Morris traversal is used (though it modifies tree temporarily).

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