← Meta Interview Insights

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

IntermediatePrefer not to say
Jun 2026

Summary

Meta software engineer coding round with two algorithm problems. Both had a brute-force-then-optimize structure which I kind of expected, but the second one tripped me up more than I'd like to admit.

Questions Asked (2)

Q1

Given a list of integers, find the indices of any three distinct elements that sum to 15. Discuss edge cases, a brute-force approach, and an optimized solution.

Algorithms & Data Structures
Author's notes

Started with the O(n^3) triple loop which they were fine with as a starting point.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and edge cases, then present a brute-force O(n^3) solution as a baseline, and finally propose an optimized O(n^2) approach using a hash set or two-pointer technique after sorting. Emphasize the trade-offs between time and space complexity, and discuss how to handle duplicates and ensure distinct indices.

Pro tip: Mention that you would first check if the array length is less than 3 and return an empty list immediately, and discuss how to handle duplicate values by storing indices in a hash map to avoid using the same element twice.

1. Clarify requirements and edge cases

Ask if the array can contain duplicates, if the indices must be distinct, and what to return if no triplet exists. Discuss edge cases like array size < 3, negative numbers, and multiple valid triplets.

2. Brute-force approach

Explain a triple nested loop that checks all combinations of three distinct indices and returns the first triplet summing to 15. Mention its O(n^3) time complexity and O(1) space complexity.

3. Optimized approach

Propose sorting the array and using a two-pointer technique for each element, or using a hash set to store complements. For each pair (i, j), check if 15 - arr[i] - arr[j] exists in a hash set of remaining elements, ensuring distinct indices. This yields O(n^2) time and O(n) space.

4. Handle duplicates and distinct indices

If using a hash set, store elements with their indices to avoid reusing the same index. If sorting, skip duplicate values to avoid redundant triplets, but ensure indices are tracked if original indices are required.

5. Analyze complexity and trade-offs

Compare the brute-force and optimized solutions in terms of time and space. Discuss when the brute-force might be acceptable (small n) and why the optimized solution is preferred for large inputs.

Key Points to Mention

  • Time and space complexity of brute-force (O(n^3) time, O(1) space) and optimized (O(n^2) time, O(n) space) solutions.
  • Handling edge cases: array length < 3, no triplet found, negative numbers, and duplicate values.
  • Ensuring distinct indices: using a hash map to store value-to-index mapping or careful pointer movement in two-pointer approach.
  • Trade-offs between sorting (O(n log n) time) and using a hash set (O(n) space) for the optimized solution.
  • Possibility of multiple valid triplets: return any one, or discuss how to find all if needed.
  • Clarifying if the input array can be modified (sorting in-place) or if extra space is allowed.

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

Q2

Given a list of lowercase words, find the maximum length of a concatenation of any subset where the final string has no repeated characters. Words with internal duplicates cannot be used.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This one is sneakier than it looks.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, filter out words with duplicate characters and represent each valid word as a bitmask of its characters. Then use dynamic programming or backtracking to explore combinations of words, ensuring no overlapping bits, and track the maximum total length. Optimize by pruning branches where the remaining words cannot improve the current best.

Pro tip: Mention that you can precompute the bitmask for each word and use memoization on the set of used characters to avoid redundant work. Also, note that the order of words doesn't matter, so you can process words in any order and use a DP over masks.

1. Filter and Encode Words

Remove any word that has repeated characters. For each remaining word, compute a bitmask representing the set of characters it contains.

2. Define State and Transition

Use a DP state that represents the set of characters used so far (as a bitmask). For each word, if its bitmask doesn't overlap with the current state, transition to a new state with the union of masks and add the word's length.

3. Choose an Algorithm

Decide between backtracking with pruning or iterative DP over all possible masks. Backtracking is simpler but may be slower; DP over masks (2^26) is too large, so use a hash map to store only reachable states.

4. Optimize with Pruning and Memoization

Sort words by length descending to try longer words first. Use memoization to cache results for each state, and prune if the current length plus the sum of remaining word lengths cannot exceed the best found so far.

5. Analyze Complexity and Trade-offs

Discuss time and space complexity. Mention that the number of valid words is limited (at most 26 characters each, so at most 26! but practically much smaller). Compare with brute force and explain why the chosen approach is efficient.

Key Points to Mention

  • Bitmask representation of character sets for efficient overlap checking.
  • Filtering out words with duplicate characters as they can never be used.
  • Dynamic programming over subsets or backtracking with memoization.
  • Pruning strategies: sorting by length, early termination when remaining words can't improve best.
  • Complexity analysis: worst-case exponential but practical due to constraints (lowercase letters, limited valid words).
  • Trade-offs between different approaches (e.g., DP vs backtracking) and how to choose based on input size.

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