Skip to content

Latest commit

 

History

History
14 lines (11 loc) · 673 Bytes

File metadata and controls

14 lines (11 loc) · 673 Bytes

Problem 6: Local Extremum Detection

Problem Statement

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 to any of the peaks. You may imagine that nums[-1] = nums[n] = -∞. In other words, an element is always considered to be strictly greater than a neighbor that is outside the array. You must write an algorithm that runs in O(log n) time.

Input Format

  • An integer array nums.

Example

Input: nums = [1, 2, 3, 1]
Output: 2 Explanation: 3 is a peak element and its index is 2.