Given an array of integers, find the index of a local minimum.
A local minimum is defined as an element that is strictly smaller than its neighbors.
Formally:
- For any index
i,A[i] < A[i-1]andA[i] < A[i+1].
You may assume:
- The array has no equal adjacent elements, i.e.,
A[i] != A[i+1]. - A valid local minimum always exists.
- The array is not necessarily sorted.
- You need to find any one local minimum.
Goal:
Return the index of one such local minimum.
Example:
Input: [9, 7, 2, 8, 5, 6]
Output: 2 # A[2] = 2 is a local minimum
You must return the index of any element that is strictly smaller than both neighbors.
Since adjacent duplicates do not exist and a local minimum is guaranteed, you can apply binary search in O(log n) to efficiently find one.
The VOprep team has long accompanied candidates through various major company OAs and VOs, including Google, Amazon, Citadel, SIG, providing real-time voice assistance, remote practice, and interview pacing reminders to help you stay smooth during critical moments. If you are preparing for these companies, you can check out our customized support plans—from coding interviews to system design, we offer full guidance to help you succeed.