← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Interviewed at Meta for a software engineer role, and the only thing I can say for certain is that LeetCode 229 came up.

Questions Asked (1)

Q1

Given an integer array, find all elements that appear more than n/3 times.

Algorithms & Data Structures
Author's notes

Classic majority vote problem extended to two candidates instead of one.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints and edge cases, then discuss the Boyer-Moore Majority Vote algorithm as the optimal solution. Explain that at most two elements can appear more than n/3 times, and use two candidates and counters to find them in O(n) time and O(1) space, followed by a verification pass.

Pro tip: Mention that the verification pass is crucial because the Boyer-Moore algorithm only guarantees candidates, not actual majorities. Also, note that using a hash map is a valid alternative but may not meet the O(1) space requirement if that's expected.

1. Clarify requirements and edge cases

Ask about input size, whether the array can be empty, and if the output order matters. Confirm that 'more than n/3 times' means strictly greater than floor(n/3).

2. Discuss possible approaches

Mention brute force (O(n^2)), hash map (O(n) time, O(n) space), and the optimal Boyer-Moore Majority Vote (O(n) time, O(1) space). Explain why the optimal is preferred.

3. Explain the Boyer-Moore algorithm

Describe maintaining two candidates and two counters. Iterate through the array: if current equals a candidate, increment its counter; else if a counter is zero, set candidate; else decrement both counters.

4. Verify candidates

After the first pass, do a second pass to count the occurrences of each candidate. Include only those with count > n/3 in the result.

5. Analyze complexity and test

State time O(n) and space O(1). Walk through a small example to demonstrate correctness and handle edge cases like empty array or no majority.

Key Points to Mention

  • At most two elements can appear more than n/3 times (since 3 * (n/3 + 1) > n).
  • Boyer-Moore algorithm generalizes to finding elements appearing more than n/k times using k-1 candidates.
  • The first pass only finds candidates; a second pass is required to confirm their counts.
  • Time complexity O(n) and space complexity O(1) for the optimal solution.
  • Edge cases: empty array, array with one element, no element exceeding n/3.
  • Alternative approach: hash map for O(n) time and O(n) space, which is simpler but less optimal.

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