← Meta Interview Insights

Meta·Software Engineer·Onsite - Coding / Algorithms·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Three coding problems at Meta for a software engineer role. All algorithmic, all required complexity analysis on the spot. Nothing behavioral, just back-to-back problem solving.

Questions Asked (3)

Q1

Given the root of an N-ary tree and two target nodes, find their lowest common ancestor. If either node doesn't exist in the tree, return null.

Algorithms & Data Structures
Author's notes

The null case is what trips people up here.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a post-order DFS that returns a status for each subtree: whether each target was found and the LCA if both are found in that subtree. At each node, combine results from children; if both targets are found and LCA not yet determined, the current node is the LCA. Handle missing nodes by returning null if either target is not found in the entire tree.

Pro tip: Clarify upfront whether the two target nodes are guaranteed to be distinct and whether the tree can be empty; this shows attention to edge cases and avoids incorrect assumptions. Also, mention that if the targets are the same node, the LCA is that node itself.

1. Clarify assumptions and edge cases

Ask if the tree can be empty, if the two targets can be the same node, and if nodes have parent pointers (which would allow a different approach). Confirm that if either node is missing, return null.

2. Choose DFS approach

Decide on a recursive post-order DFS that processes children first and returns information about found targets and LCA. This naturally handles N-ary trees by iterating over all children.

3. Define recursive function

The function returns a pair: (foundA, foundB, lca). If the current node is one of the targets, mark it as found. Recursively process each child and merge results. If both targets are found in the current subtree and lca is not set, set lca to the current node.

4. Handle missing nodes

After the DFS, if either target was not found in the entire tree, return null. Otherwise, return the LCA found.

5. Analyze complexity and test

State that time complexity is O(N) since each node is visited once, and space complexity is O(H) for recursion stack, where H is tree height. Walk through a small example to verify correctness.

Key Points to Mention

  • Post-order DFS to combine results from children
  • Tracking found status for each target separately
  • Identifying LCA when both targets are found in a subtree
  • Handling the case where either target is missing
  • Time and space complexity analysis
  • Edge cases: empty tree, same target node, target is root

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

Q2

You have two separately sorted lists of non-overlapping intervals. Merge them into a single sorted list with no overlapping intervals.

Algorithms & Data Structures
Author's notes

Classic two-pointer merge but with the overlap-collapsing logic on top.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a two-pointer technique to traverse both sorted interval lists simultaneously, merging intervals on the fly by comparing start times and handling overlaps. Maintain a result list and a 'current' interval that is extended when overlaps occur.

Pro tip: Clarify upfront whether the input lists are truly non-overlapping and sorted, and confirm the expected output format (e.g., list of intervals). This shows attention to detail and avoids incorrect assumptions.

1. Clarify and Validate Inputs

Confirm that each list is sorted and internally non-overlapping, and ask about edge cases like empty lists or single intervals. This ensures you understand the problem constraints.

2. Initialize Pointers and Result

Set two pointers i and j to 0 for the two lists, and create an empty result list. Also initialize a 'current' interval to None to track the merged interval being built.

3. Merge Intervals with Two Pointers

While both pointers are within bounds, pick the interval with the smaller start time. If it overlaps with 'current', merge them by updating the end; otherwise, add 'current' to result and set 'current' to the new interval. Advance the corresponding pointer.

4. Process Remaining Intervals

After one list is exhausted, continue processing the remaining intervals from the other list in the same manner, merging with 'current' as needed.

5. Finalize and Return

After all intervals are processed, add the last 'current' interval to the result if it exists, and return the merged list.

Key Points to Mention

  • Two-pointer technique for merging sorted lists
  • Overlap condition: next.start <= current.end
  • Time complexity: O(n + m) where n and m are list lengths
  • Space complexity: O(n + m) for the output list
  • Handling edge cases: empty lists, single interval, no overlaps
  • Maintaining sorted order by always picking the interval with the smaller start time

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

Q3

Given a list of lowercase words, find the largest subset where no letter appears more than once across all chosen words combined. Return the total character count of that subset.

Algorithms & Data Structures
Author's notes

This one is a bitmask DP problem and I did not see it immediately.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model each word as a 26-bit mask of its letters, discarding any word with duplicate letters. Then use backtracking with pruning to explore subsets of valid words, tracking the combined mask and total character count to find the maximum. Alternatively, use DP over masks if the number of valid words is small.

Pro tip: Precompute valid words and their masks first; this reduces the search space and avoids repeated duplicate checks. Also, sort words by length descending to find a good initial solution early, which improves pruning.

1. Preprocess words into bitmasks

For each word, compute a 26-bit integer where each bit represents a letter. If a word has duplicate letters, discard it since it can never be part of a valid subset.

2. Choose search strategy

Decide between backtracking with pruning or dynamic programming over masks. Backtracking is simpler and works well for typical constraints; DP is better if the number of valid words is small.

3. Implement backtracking with pruning

Recursively consider each valid word: include it only if its mask doesn't overlap with the current combined mask. Track the maximum total length. Prune branches where the remaining possible length cannot exceed the current best.

4. Optimize with sorting and memoization

Sort words by length descending to find a strong initial solution early. Optionally, memoize states (index, combined mask) if the same state can be reached multiple times.

5. Return the maximum total length

After exploring all valid subsets, return the maximum total character count found.

Key Points to Mention

  • Bitmask representation for efficient letter set operations
  • Discarding words with duplicate letters upfront
  • Backtracking with pruning to reduce search space
  • Time complexity analysis: O(2^N) worst-case but pruned; N is number of valid words
  • Space complexity: O(N) for recursion stack plus masks
  • Edge cases: empty list, all words invalid, single word

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