FastPrepFind Peak Element
Problems/Find Peak Element

Find Peak Element

Indeed logoIndeed● MediumNEW GRADPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: A report mentions a phone screen and names its task only by a coded LeetCode number, with the digits 1, 6 and 2 written as stand-in characters (a spoken form, a homophone and a formal numeral). LeetCode 162 is Find Peak Element, and this version is built from that title.

The report gives no statement, examples or limits. Here, a peak is greater than each neighbor it has, and adjacent values are never equal. The usual version can have several peaks and accepts any of them; here every array has exactly one peak, so the answer is unique. The value range and the length limit are practice choices.

The judged task matches the report at about 70%.

A peak in an integer array is a value that is strictly greater than each neighbor it has. The first value has only a right neighbor and the last value has only a left neighbor, so you can think of the positions just outside the array as minus infinity.

You are given nums. Adjacent values are never equal, and exactly one index is a peak. Return that index.

Exactly one peak means the values strictly rise up to the peak and strictly fall after it. Either part may be empty, so the peak can be the first or the last index.

Function

findPeakElement(nums: int[]) → int

Examples

Example 1

nums = [1,5,8,6,2]return = 2

8 at index 2 is greater than both neighbors, 5 and 6. Every other value has a larger neighbor.

Example 2

nums = [3,7,11,20]return = 3

The values only go up. 20 at index 3 is greater than its left neighbor 11, and it has no right neighbor, so it is the peak.

Example 3

nums = [6]return = 0

A single value has no neighbors, so index 0 is the peak.

Constraints

  • 1 <= nums.length <= 10^4
  • -2^31 <= nums[i] <= 2^31 - 1
  • nums[i] != nums[i + 1] for every valid i.
  • Exactly one index is a peak.

More Indeed problems

  • Insert into an Unrolled Linked ListPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Course Completion OrderPHONE SCREEN · Seen May 2025
  • Recipes You Can PreparePHONE SCREEN · Seen May 2025
All Indeed interview questionsSee Indeed hiring insights
Saved
class Solution {
    public int findPeakElement(int[] nums) {
        // Write your code here.
    }
}
Checking account…