Locate a Local Maximum in an Array

Asked at Meta · Coding Questions · Difficulty: Hard

Given a list of numbers in which no two neighbours are equal, return the position of any element that is larger than both of its neighbours. The list is treated as if it were surrounded by negative infinity, so the first and last elements only need to beat their single real neighbour. The catch is speed: you may read only about two elements per halving of the search range, so the budget in Rule 3 is tight.

Loading the problem…