FunctionRacerProblemsRace

Peak of a Mountain

EasySorting and searchingPython, JavaScript, TypeScript, Java, C++

arr is a mountain: it strictly increases up to one peak and then strictly decreases, and it has at least 3 items. Return the index of the peak.

This can be done with binary search, but a plain loop is fine too.

Example 1

arr [0,2,1,0]
returns 1

The peak 2 is at index 1.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Sorting and searching problems