← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Meta software engineer interview with two coding problems. One tree traversal question and one binary search problem where they specifically wanted O(log n) complexity, not just a working solution.

Questions Asked (2)

Q1

Given a binary tree where each node contains a single digit, compute the sum of all numbers formed by root-to-leaf paths.

Algorithms & Data Structures
Author's notes

Pretty classic tree recursion problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a depth-first search (DFS) traversal, passing the current number formed so far (as an integer) down the recursion. At each leaf, add the current number to a running total. Return the total sum.

Pro tip: Clarify edge cases upfront: what if the tree is empty? What if a node has only one child? Also, mention that you can avoid integer overflow by using modulo or by noting constraints, but typically the sum fits in a 32-bit integer for reasonable tree depths.

1. Understand the problem

Restate the problem: each root-to-leaf path forms a number by concatenating digits. We need the sum of all such numbers. Confirm with the interviewer if the tree can be empty or if digits are 0-9.

2. Choose traversal method

Decide between DFS (recursive or iterative) and BFS. DFS is natural because we need to carry the current number down the path. Mention that BFS would require storing the current number with each node in the queue.

3. Define recursive helper

Write a helper function that takes a node and the current number formed so far. At each node, update current number as current * 10 + node.val. If leaf, add to sum; else recurse on children.

4. Handle base cases

If node is null, return 0. If leaf, return the current number. Otherwise, return sum of left and right subtrees. This naturally accumulates the total.

5. Analyze complexity

Time complexity: O(N) where N is number of nodes, as each node is visited once. Space complexity: O(H) for recursion stack, where H is tree height (worst case O(N) for skewed tree).

Key Points to Mention

  • Depth-first search (DFS) traversal
  • Passing current number as parameter (current * 10 + node.val)
  • Leaf node condition: node.left == null && node.right == null
  • Recursive solution with base case for null node
  • Time complexity O(N) and space complexity O(H)
  • Potential integer overflow and how to handle it (e.g., using long or modulo)

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

Q2

Given a sorted array and a target value, return all indices where the target appears. The catch: they want O(log n) time, not a linear scan.

Algorithms & Data Structures
Author's notes

The array being pre-sorted is the hint, but my first instinct was still to just iterate through.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use binary search to find the first and last occurrence of the target, then return the range of indices. This achieves O(log n) time by performing two modified binary searches instead of scanning linearly.

Pro tip: Clarify with the interviewer whether the output should be a list of indices or a range (start, end) — this shows attention to detail and can simplify the solution. Also, mention edge cases like empty array or target not present.

1. Clarify requirements and edge cases

Confirm the expected output format (list of indices vs. range) and discuss edge cases such as empty array, target absent, or all elements equal to target.

2. Design binary search for first occurrence

Modify binary search to find the leftmost index of the target by continuing to search left even when the target is found.

3. Design binary search for last occurrence

Similarly, modify binary search to find the rightmost index by continuing to search right when the target is found.

4. Combine results and handle absence

If both searches return valid indices, return the range or list of indices; otherwise, return an empty list or indicate absence.

5. Analyze complexity and test

State that time complexity is O(log n) and space is O(1) (or O(k) for output). Walk through a few test cases to verify correctness.

Key Points to Mention

  • Binary search modification for first and last occurrence
  • Time complexity O(log n) and space complexity O(1) (excluding output)
  • Handling duplicates and ensuring all indices are captured
  • Edge cases: empty array, target not found, single element
  • Comparison with linear scan and why O(log n) is required
  • Potential to return a range instead of a list to save space

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