Quant Memo
Coding/●●●●●

Find a peak element

Asked at Citadel

An array has no two adjacent elements equal. A peak is an index whose value is strictly greater than both neighbors, treating the out-of-bounds edges as -\infty. There may be several peaks; you only need to return one.

a = [1, 2, 3, 1]           -> 2   (value 3)
a = [1, 2, 1, 3, 5, 6, 4]  -> 5   (value 6; index 1 also valid)
a = [5, 4, 3]              -> 0

Return the index of any peak. Aim for O(logn)O(\log n).

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions