Find Peak Element
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.

30:00

Find Peak Element
medium
Topics
Companies

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.

Example 1:
Input: {"nums":[1,2,3,1]}
Output: 2
Constraints:
  • 1nums.length10001 \leq \text{nums.length} \leq 1000

  • 231nums[i]2311-2^{31} \leq \text{nums}[i] \leq 2^{31} - 1

  • nums[i]nums[i+1]\text{nums}[i] \neq \text{nums}[i+1] for all valid ii.

Input
arr ={"nums":[1,2,3,1]}
Target: 0

1

L

2

3

1

R
Variables
No variables to display
DepthFunction Call
Stack empty
0/4