Find Peak Element
Advanced
In this fun coding challenge, we'll traverse through a list of numbers to find a "peak" element. A peak element is one that is strictly greater than its neighbors. Your task is to identify and return the index of any one peak element in a list of numbers.
For simplicity, let's assume that the numbers are unique, and the list is never empty. A peak element can be at any position in the list.
Example:
find_peak_element([1, 3, 20, 4, 1, 0]) # Returns 2 as '20' is a peak element because it is greater than '3' and '4'. find_peak_element([10, 7, 8, 20, 15]) # Returns 3 as '20' is a peak because it is greater than '8' and '15'.
In the case where the peak is at the beginning or end of the list:
find_peak_element([5, 3, 2, 1]) # Returns 0 since '5' is a peak because there are no elements before it. find_peak_element([1, 2, 3, 6]) # Returns 3 since '6' is a peak because there are no elements after it.
Help find the peaks and practice coding with this interesting challenge!
Inputs
Arg 1:
[1,3,20,4,1,0]Expected Output
2Actual Output