← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Meta SWE interview with a tricky algorithmic twist. The classic 'find the unique element' problem but with an O(log n) constraint, which changes everything about how you approach it.

Questions Asked (1)

Q1

You have an array where every number appears exactly twice except for one. Find the unique number in O(log n) time.

Algorithms & Data Structures
Author's notes

My first instinct was XOR, which gets you there in O(n).

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify that the O(log n) requirement implies the array is sorted, as binary search is otherwise impossible. Then, explain that in a sorted array, the unique element can be found by comparing pairs at even indices; use binary search to discard halves where all elements appear in pairs.

Pro tip: Always state your assumptions explicitly—here, that the array is sorted. If the interviewer confirms, proceed; if not, discuss the impossibility of O(log n) and offer an O(n) XOR solution as a fallback.

1. Clarify assumptions

Ask if the array is sorted. If not, explain that O(log n) is impossible and propose an O(n) solution using XOR.

2. Identify the pattern

In a sorted array, all elements before the unique element appear in pairs at indices (0,1), (2,3), etc. After the unique element, the pairing shifts.

3. Design binary search

Use binary search on even indices. If the element at mid equals the next element, the unique is to the right; otherwise, it's to the left.

4. Handle edge cases

Consider arrays of length 1, unique at start or end, and ensure mid is always even to maintain pair alignment.

5. Analyze complexity

Explain that each step halves the search space, giving O(log n) time and O(1) space.

Key Points to Mention

  • Assumption of sorted array for O(log n) feasibility
  • Binary search on even indices to check pair integrity
  • Comparison of mid with mid+1 to decide search direction
  • Edge cases: unique at first or last position, single-element array
  • Time complexity O(log n) and space complexity O(1)
  • Fallback O(n) XOR solution if array is unsorted

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