A hiking trail is described by n elevation readings taken in order. The elevations strictly increase up to a single summit and then strictly decrease afterward (either the rising part or the falling part may be empty). Because the profile is strictly increasing then strictly decreasing, there is exactly one summit: the position holding the unique maximum elevation.
Print the 0-indexed position of that summit.
Line 1: an integer n, the number of readings.
Line 2: n space-separated integers, the elevations in trail order.
A single integer: the 0-indexed position of the summit.
Example 1
Input
5 1 3 7 4 2
Expected
2
Explanation
Elevations rise 1, 3, 7 then fall 4, 2. The summit 7 sits at index 2.
Example 2
Input
1 9
Expected
0
Explanation
A single reading is itself the summit at index 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →