Find Peak Element (Binary Search)

Medium

📝 Description

A peak element is greater than its neighbors. Find any peak in O(log n) time.

Input Format

[a1, a2, ..., an] (array where nums[i] ≠ nums[i+1])

Output Format

index of any peak

Constraints

1 ≤ n ≤ 1000, -2^31 ≤ nums[i] ≤ 2^31-1

🔍 Sample Input

[1,2,3,1]
            

✅ Sample Output

2
            

Code Editor

Please login to run and submit code.

Shortcuts: Ctrl+Enter to submit, Ctrl+Shift+R to run