Peak Element Finder
Given an array of integers, find a peak element and return its index. A peak element is one which is greater than its neighbors. For array boundaries, only one neighbor exists.
Note: If there are multiple peak elements, you may return the index of any of them.
[ 1, 3, 20, 4, 1, 0 ]
Explanation. The element at index 2 is 20, which is greater than its neighbors 3 and 4.
[ 10, 20, 15 ]
Explanation. The peak element 20 is at index 1, greater than its neighbor 10.
[ 2, 2, 2, 2, 3, 2 ]
Explanation. The peak element 3 is at index 4, surrounded by 2s.
Follow-up: Can you implement your solution in a way that it works in logarithmic time complexity?
- The array will contain at least one element and may contain up to 1000 elements. - All elements will be integers.
- Views
- 3