I knew binary search was the answer pretty fast, the O(log n) hint basically gives it away.
Use a binary search variant that compares the middle element with its neighbors to determine which half contains a peak. If the middle is greater than both neighbors, return it; otherwise, move toward the side with the larger neighbor. This works because the array has no equal adjacent elements, guaranteeing a peak exists in the chosen half.
Pro tip: Clarify the boundary condition: treat out-of-bounds as negative infinity, so the first or last element can be a peak if it's greater than its only neighbor. Also, mention that this approach finds *a* peak, not necessarily the global maximum.
Restate the problem to ensure understanding: find any peak in O(log n) time, with no two adjacent elements equal, and boundary elements compared to -∞. Confirm that returning any peak is acceptable.
Describe how to use binary search: pick the middle index, compare its value with its left and right neighbors. If it's greater than both, it's a peak. Otherwise, move to the side where the neighbor is greater.
Discuss how to handle indices at the boundaries: treat out-of-bounds as -∞, so the first element is a peak if it's greater than the second, and similarly for the last element. Ensure the algorithm works for arrays of size 1 and 2.
Trace the algorithm on a sample array (e.g., [1,3,2,4,5,6,7,8]) to demonstrate correctness and the O(log n) time complexity. Show how the search space halves each step.
State that time complexity is O(log n) and space is O(1). Mention that this approach relies on the guarantee of no equal adjacent elements, and that it finds a local peak, not necessarily the global maximum.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.