Skip to main content

80. Find Peak Element

mediumAsked at Plaid

Find a peak element in an array (one whose value is strictly greater than its neighbors). Plaid asks this as a binary-search-on-properties problem — exactly the shape they use to find traffic peaks in a time-bucketed transaction-rate series.

By Alex Chen, Founder, InterviewChamp.AI · Last verified

Source citations

Public interview reports confirming this problem appears in Plaid loops.

  • Glassdoor (2025)Plaid SWE II OA — traffic-peak variant.
  • LeetCode Discuss (2026)Plaid binary-search property.

Problem

A peak element is an element that is strictly greater than its neighbors. Given a 0-indexed integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index of any of the peaks. You may imagine that nums[-1] = nums[n] = -Infinity. You must write an algorithm that runs in O(log n) time.

Constraints

  • 1 <= nums.length <= 1000
  • -2^31 <= nums[i] <= 2^31 - 1
  • nums[i] != nums[i + 1] for all valid i.

Examples

Example 1

Input
nums = [1,2,3,1]
Output
2

Example 2

Input
nums = [1,2,1,3,5,6,4]
Output
5 (or 1)

Approaches

1. Linear scan

Walk and check each.

Time
O(n)
Space
O(1)
function findPeakElement(nums) {
  for (let i = 0; i < nums.length; i++) {
    if ((i === 0 || nums[i] > nums[i - 1]) && (i === nums.length - 1 || nums[i] > nums[i + 1])) return i;
  }
}

Tradeoff: Misses the O(log n) requirement.

2. Binary search on slope

Compare nums[mid] to nums[mid+1]. If ascending, peak is to the right. If descending, peak is at mid or to the left.

Time
O(log n)
Space
O(1)
function findPeakElement(nums) {
  let lo = 0, hi = nums.length - 1;
  while (lo < hi) {
    const mid = (lo + hi) >> 1;
    if (nums[mid] < nums[mid + 1]) lo = mid + 1;
    else hi = mid;
  }
  return lo;
}

Tradeoff: Logarithmic. The slope direction tells us which half must contain a peak (by IVT-like argument).

Plaid-specific tips

Plaid grades this on whether you can articulate why binary search works on an unsorted array. Bonus signal: prove correctness — if nums[mid] < nums[mid+1], the right half must contain a peak (it's ascending into something that eventually must descend by the -Infinity boundary). Connect to finding traffic peaks in a transaction-rate time series.

Common mistakes

  • Comparing nums[mid] to nums[mid-1] — fails at boundary mid = 0.
  • Using lo <= hi — same off-by-one as LC 153.
  • Trying to find the global max — the problem only requires a local peak, which is faster to find.

Follow-up questions

An interviewer at Plaid may pivot to one of these next:

  • Find any local minimum.
  • Find all peaks in O(n).
  • Find a peak in a 2D matrix (LC 1901).

Solve it now

Free. No sign-up. Python and JavaScript run instantly in your browser.

Output

Press Run or Cmd+Enter to execute

FAQ

Why is binary search valid on an unsorted array?

The property 'a peak exists in this slice' is monotonic across the slope direction. We're not searching for sorted-order; we're searching on the slope.

What if all elements are equal?

The constraint says no two adjacent elements are equal, so this case is excluded. With duplicates allowed, the worst case becomes O(n).

Practice these live with InterviewChamp.AI

Drill Find Peak Element and other Plaid interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.

Practice these live with InterviewChamp.AI →