Find Peak Element

Medium Solved

Description

A peak element is an element that is strictly greater than its neighbors.

Given an 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 assume nums[-1] = nums[n] = -∞.

Input format:

  • Line 1: JSON array of integers

Example

Input:
[1,2,3,1]

Output:
2

Note:

Your program must print a single integer representing the index of any peak element.

No submissions yet.

Discuss binary search optimization and edge cases.

Test Cases