So, I am given an unsorted list A = (a1, a2, ..., an) with n distinct elements. My goal here is to find the middle index i (1 <= i <= n) of a sequence where ai-1 < ai and ai > ai+1. The algorithm should run in O(log(n)) worst case. It is also given that a0 = an+1 = -inf.
So basically i need to find an index surrounded by smaller number than itself, such as {1,5,3}, where 1 and 3 are smaller than 5.
Example:
Input: A = {1, 2, 4, 5, 3, 7, 6}
Output: 4 (because of the sequence {4, 5, 3})
This algorithm would be extremly easy if the worst case was to be O(n), where a simple for-loop could check that sequence, but I'm having a hard time with the fact that it needs to run worst case O(log(n)).