← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Meta SWE coding round, one question the whole session. The problem sounds straightforward until you realize they want O(log n) and suddenly you're staring at binary search trying to convince yourself why it works.

Questions Asked (1)

Q1

Given an integer array where no two adjacent elements are equal, find any peak element. A peak is an index where the value is greater than both its neighbors, with the boundaries treated as negative infinity. Solve it in O(log n).

Algorithms & Data Structures
Author's notes

I knew binary search was the answer pretty fast but explaining WHY it works took me longer than I'd like to admit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use binary search to find a peak by comparing the middle element with its neighbors. If the middle is greater than both neighbors, return it; otherwise, move towards the side with the larger neighbor. This works because the array has no equal adjacent elements, guaranteeing a peak exists in the direction of ascent.

Pro tip: Clarify edge cases upfront: arrays of length 1 or 2, and how boundaries are treated as negative infinity. This shows attention to detail and avoids off-by-one errors.

1. Understand the problem and constraints

Restate the problem: find any peak in O(log n) time. Note that adjacent elements are never equal, and boundaries are negative infinity, so the ends can be peaks if they are greater than their single neighbor.

2. Choose binary search as the strategy

Explain that binary search is suitable because the peak condition allows us to discard half the array based on local comparisons, achieving logarithmic time.

3. Define the binary search logic

While left <= right, compute mid. If mid is a peak (greater than both neighbors, considering boundaries), return mid. Otherwise, if the left neighbor is greater, search left; else search right.

4. Handle edge cases

Check for arrays of length 1 (return 0) and length 2 (return index of larger element). Also ensure boundary checks when mid is at the start or end.

5. Analyze complexity and test

State that time complexity is O(log n) and space is O(1). Walk through a small example to verify correctness.

Key Points to Mention

  • Binary search reduces the search space by half each iteration.
  • The peak condition: element greater than both neighbors (or single neighbor at boundaries).
  • No two adjacent elements are equal, ensuring a peak exists in the direction of the larger neighbor.
  • Boundary handling: treat out-of-bounds as negative infinity.
  • Time complexity: O(log n), space complexity: O(1).
  • Edge cases: array length 1 or 2.

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