FastPrepFind Peak Element
Problems/Find Peak Element

Find Peak Element

Microsoft logoMicrosoft● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The 45-minute technical round of a Microsoft software engineering internship process, as described in a review, included a peak-element question. The review mentions a binary-search speedup.

The review gives no details. Many arrays have several peaks, and any of them is usually accepted, but this judge needs one answer. So here the array has exactly one peak: it strictly rises and then strictly falls (either part may be empty). Positions outside the array count as minus infinity, and you return the peak's index. There are 1 to 10^4 values from -10^9 to 10^9.

Our version is about 85% the same as the reported question.

A peak is an element that is strictly greater than its neighbours. Treat the positions just outside the array as -∞, so the first or last element can be a peak.

You are given an integer array nums that has exactly one peak. Return the index of the peak.

Aim for O(log n) time.

Function

findPeakElement(nums: int[]) → int

Examples

Example 1

nums = [1,3,5,4,2]return = 2

The values rise to 5 and then fall. nums[2] = 5 is greater than both neighbours, 3 and 4, so the answer is 2.

Example 2

nums = [2,4,6,8]return = 3

The values only rise. The last element, 8, is greater than its left neighbour, and there is no right neighbour, so it counts as a peak. The answer is 3.

Example 3

nums = [9]return = 0

A single element has no neighbours, so it is the peak. The answer is 0.

Constraints

  • 1 <= nums.length <= 10^4
  • -10^9 <= nums[i] <= 10^9
  • nums[i] != nums[i + 1] for every valid i.
  • nums has exactly one peak: it strictly rises and then strictly falls, and either part may be empty.

More Microsoft Onsite Interview questions

  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
  • Totals from a Tiered Rate TableONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Search a Row- and Column-Sorted MatrixByteDance · ONSITE INTERVIEWByteDance interview questions
  • First and Last Target Position in a Mountain ArrayGoogle · ONSITE INTERVIEWGoogle interview questions
  • 3Sum SmallerSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Peak of an Increasing-Then-Decreasing ArraySnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
  • Online Meeting Scheduler with Fixed RoomsUber · ONSITE INTERVIEWUber interview questions
  • Search in a Rotated Sorted ArrayAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Search in Rotated Sorted ArrayKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Find First and Last Position in Sorted ArrayPaytm · ONSITE INTERVIEWPaytm interview questions
  • Detect a Silent SensorConfluent · ONSITE INTERVIEWConfluent interview questions
  • Search in Rotated Sorted ArrayCapgemini · ONSITE INTERVIEWCapgemini interview questions

Interview reports that mention this question

  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

Microsoft interview experiences

  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int findPeakElement(int[] nums) {
        // Write your code here.
    }
}
Checking account…