Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Peak Index in a Mountain Array

Medium

Topics
ArrayBinary Search

An array nums is a mountain: it strictly increases up to a unique peak and then strictly decreases. Return the index of the peak element. Solve in O(log n) time.

Example 1

Input:  nums = [0,1,0]
Output: 1

Example 2

Input:  nums = [0,2,1,0]
Output: 1

Example 3

Input:  nums = [0,10,5,2]
Output: 1

Constraints

  • 3 <= nums.length <= 10^5
  • 0 <= nums[i] <= 10^6
  • nums forms a mountain (unique peak).
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access