...

/

Challenge: Find the Peak Element

Challenge: Find the Peak Element

In this lesson, we will find the peak element in a given list, which is element that is greater than both of its neighbors.

Peak element

A peak element in a list is the element that is greater than or equal to its neighbors. For elements at the end of a list, we only consider its single neighbor.

Problem statement:

Given a list and its size, return one of its peak elements.

Input

  • lst (list of integers)

Output

  • integer (a peak element or -1 if there is no peak element)

Sample input

lst = [47, 85, 85, 35, 49, 49]

Sample output

result = 85
or
result = 49

Coding challenge

First, take a close look at this problem and design a step-by-step algorithm before jumping to the implementation. This problem is designed for your practice, so try to solve it on your own first. If you get stuck, you can always refer to the solution provided in the solution section. Good luck!