Given an array of integers. Find a peak element in it. An array element is peak if it is NOT smaller than its neighbors. For example, for input array {5, 10, 20, 15}, 20 is the only peak element.
For corner elements, we need to consider only one neighbor. Following corner cases give better idea about the problem.
1) If input array is sorted in strictly increasing order, the last element is always a peak element. For example, 50 is peak element in {10, 20, 30, 40, 50}. 2) If input array is sorted in strictly decreasing order, the first element is always a peak element. 100 is the peak element in {100, 80, 60, 50, 20}.
3) If all elements of input array are same, every element is a peak element.
Sample input
5,10,20,15
100,80,60,50,20
10,20,30,40,50
Sample output
Find it! The peak element is 20
Find it! The peak element is 100 Find it! The peak element is 50
Reviews
There are no reviews yet.