# Peak element Intuition

Your goal is to find the peak element in a given collection of elements.

If an element is greater or equal to its neighbors then it can be considered as a peak element.

What if I could randomly pick any element, can something be said about that element from checking its neighbors?

# Possibility 1:

An element has two neighbors and both are less than or equal to it. This is then already the peak element. Green is the current element and blue colored are the neighboring elements

# Possibility 2:

One alternative is when you have a single neighbor on the left and the current element is greater than or equal to it.

The other alternative is when you have a single neighbor on the right and the current element is greater than or equal to it.

# Possibility 3:

Here you have a neighbor on the left that is greater than or equal to the current element. Green is the current element, blue are the neighbors and yellow are the possible elements for the neighbor that is greater than current.

Can we safely move to that greater neighbor, hence, making a decision to eliminate the current element and all neighbors on the right?

Let’s find out. If yellow-colored elements are the two probable neighbors of the greater neighbor. Then if the below yellow neighbor is considered, then we can say this blue element is the peek, or else we can extend the same reasoning to the other greater yellow neighbor, where the blue element becomes the green element (current) and the greater yellow neighbor becomes the blue element (greater neighbor). Therefore, we can conclude, that the greater neighbor side should definitely have a peek element.

If this reminds you of the binary search, then you are spot on, as we are similarly eliminating half the search space in each step.

The code should not be a big leap from here.