FunctionRacerProblemsRace

First Peak

EasyArraysPython, JavaScript, TypeScript, Java, C++

A peak of the list nums is an item strictly bigger than each neighbour it has (the first item only has a right neighbour and the last item only has a left neighbour). A list with one item has its single item as a peak.

Return the index of the first (leftmost) peak, or -1 if there is none.

Example 1

nums [1,3,2,4,1]
returns 1

3 is bigger than 1 and 2, so index 1.

Example 2

nums [2,2,2]
returns -1

No item is strictly bigger than its neighbours.

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 Arrays problems