FastPrepFind a Peak Element
Problems/Find a Peak Element

Find a Peak Element

Fox Corporation logoFox Corporation● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source report identifies the linked Find Peak Element task. The callable signature, examples, and execution bounds reuse the equivalent reviewed FastPrep task; estimated source fidelity is 95%.

Given an integer array nums, return the index of its peak element. A peak is strictly greater than each neighbor that exists.

For this exercise, assume a missing neighbor beyond either endpoint has value negative infinity, adjacent values are different, and the array has exactly one peak. Your algorithm should run in O(log n) time.

Function

findPeakElement(nums: int[]) → int

Examples

Example 1

nums = [1,2,3,1]return = 2

The value 3 is greater than both adjacent values.

Example 2

nums = [9,6,2]return = 0

The left endpoint is greater than its only neighbor.

Example 3

nums = [4]return = 0

A one-element array has a peak at index 0.

Constraints

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

More Fox Corporation problems

  • Merge Overlapping IntervalsPHONE SCREEN · Seen Sep 2026
  • S-Shaped Matrix TraversalPHONE SCREEN · Seen Sep 2026
  • Count Communicating ServersPHONE SCREEN · Seen Sep 2026
See Fox Corporation hiring insights
Saved
class Solution {
    public int findPeakElement(int[] nums) {
        // Write your code here.
    }
}
Checking account…