← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Meta SWE coding round with two problems back to back. The first was a classic array problem and the second was a tree traversal that required returning the actual path, not just the length, which tripped me up a bit.

Questions Asked (2)

Q1

Given a binary array of 0s and 1s, find the maximum length of a contiguous subarray with an equal number of 0s and 1s.

Algorithms & Data Structures
Author's notes

Prefix sum with a hash map is the clean solution here.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Transform the problem by treating 0s as -1 and 1s as +1, then find the longest subarray with sum 0. Use a hash map to store the first occurrence of each prefix sum, and for each index, check if the current prefix sum has been seen before; if so, update the maximum length. This yields an O(n) time and O(n) space solution.

Pro tip: Start by discussing the brute-force O(n^2) approach to show understanding, then optimize to O(n) using prefix sums and a hash map. Emphasize that the key insight is converting 0s to -1, which transforms the problem into finding the longest subarray with sum zero.

1. Clarify and Restate

Confirm the problem: given a binary array, find the maximum length of a contiguous subarray with equal number of 0s and 1s. Ask about edge cases like empty array or no such subarray.

2. Brute Force Approach

Mention that a naive solution checks all subarrays, counting 0s and 1s, which takes O(n^2) time. This shows you can think of a baseline.

3. Optimize with Prefix Sums

Explain the transformation: replace 0 with -1. Then the problem reduces to finding the longest subarray with sum 0. Use a hash map to store the first index where each prefix sum occurs.

4. Algorithm Walkthrough

Initialize a hash map with {0: -1} to handle subarrays starting at index 0. Iterate through the array, maintain a running sum, and for each index, if the sum is in the map, update max length; else, store the sum with the current index.

5. Complexity and Edge Cases

State that time complexity is O(n) and space is O(n). Discuss edge cases: all 0s or all 1s (result 0), and arrays where the entire array has equal counts.

Key Points to Mention

  • Transforming 0s to -1 to convert the problem into finding the longest subarray with sum 0.
  • Using a hash map to store the first occurrence of each prefix sum.
  • Initializing the hash map with {0: -1} to handle subarrays starting from the beginning.
  • Time complexity O(n) and space complexity O(n).
  • Handling edge cases such as no valid subarray (return 0) and the entire array being valid.
  • The importance of storing only the first occurrence to maximize length.

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

Q2

Given a binary tree, find the longest strictly increasing downward path (parent to child) and return the actual node values along that path, not just the length.

Algorithms & Data Structures
Author's notes

The 'return the path' part is what got me.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a post-order DFS that returns the longest strictly increasing downward path starting at each node, and track the global maximum path. At each node, compare its value with children: if child value > node value, extend the child's path; otherwise start a new path of length 1. Store the actual node values in the returned path to reconstruct the final answer.

Pro tip: Clarify whether the path must be strictly increasing and whether it can go through a node with only one child; also mention that storing paths as lists simplifies reconstruction but may use O(n) space in the worst case, so you can optimize by storing parent pointers if needed.

1. Clarify the problem

Confirm that the path must be strictly increasing (parent value < child value) and that it can start and end at any nodes. Ask if the tree can be empty or have duplicate values.

2. Define recursive function

Design a DFS function that returns the longest strictly increasing path starting from the current node as a list of values. The path includes the current node and extends to at most one child (since it's a downward path).

3. Compute at each node

Recursively get paths from left and right children. If a child's value is greater than the current node's value, the path can be extended by prepending the current node to that child's path. Choose the longer valid extension (or start a new path of length 1 if none).

4. Track global maximum

Compare the length of the path starting at the current node with the global maximum length. If it's longer, update the global maximum and store the actual path.

5. Return result

After the DFS completes, return the stored global maximum path. Discuss time and space complexity: O(n) time and O(h) space for recursion, plus O(n) for storing paths in the worst case.

Key Points to Mention

  • Strictly increasing condition: parent value < child value
  • Downward path: only from parent to child, no backtracking
  • Post-order DFS to combine results from children
  • Storing actual node values in the returned path for reconstruction
  • Time complexity O(n) and space complexity O(h) for recursion stack
  • Edge cases: empty tree, single node, all decreasing values

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