← Meta Interview Insights

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

Intermediate
Jul 2026

Summary

Meta SWE coding round, one question that looks like an intersection problem but actually wants a union. Pretty quick once you read it carefully, though the mislabeling is a little annoying.

Questions Asked (1)

Q1

Given two integer arrays, return an array containing all unique elements from both arrays combined (their union), despite the problem being labeled as an intersection.

Algorithms & Data Structures
Author's notes

The name threw me off for a second.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the discrepancy between the problem label and the actual requirement, confirming that the expected output is the union of unique elements. Then, propose an efficient solution using a hash set to collect unique elements from both arrays, and discuss time and space complexity. Finally, walk through an example to demonstrate correctness.

Pro tip: Mention that in real-world scenarios, ambiguous problem statements are common, so it's crucial to confirm requirements with stakeholders before coding. Also, note that using a hash set is optimal for average-case O(n+m) time, but if the arrays are sorted, a two-pointer approach could be more space-efficient.

1. Clarify the Problem

Point out the mismatch between the label 'intersection' and the described output 'union', and ask the interviewer to confirm the expected behavior.

2. Discuss Approaches

Propose using a hash set to store unique elements from both arrays, then convert to an array. Mention alternative approaches like sorting and two pointers if the arrays are already sorted.

3. Analyze Complexity

State that the hash set approach runs in O(n+m) average time and O(n+m) space, while the two-pointer approach on sorted arrays uses O(1) extra space but O(n log n + m log m) time if sorting is needed.

4. Code and Test

Write clean code for the chosen approach, handling edge cases like empty arrays or duplicates. Walk through a small example to verify correctness.

Key Points to Mention

  • Hash set for O(1) average-time insertions and lookups
  • Time complexity: O(n + m) average case
  • Space complexity: O(n + m) for the set and output array
  • Edge cases: empty arrays, all duplicates, negative numbers
  • Alternative two-pointer approach for sorted arrays
  • Importance of clarifying ambiguous requirements

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