I’m looking for an algorithm that runs in O(log(n)) that can find the maximum of a list that looks like this:
Here is the same example but in the form of a list (but I find it less easy to look at so I decided to make the image above):
[4, 5, 6, 1, 2, 3]
Basically it would be monotonous if we were to “rotate it” the right amount. It could also be simply a increasing sequence in the particular case where we do not need to rotate it.
I thought about applying ternary search but the problem is that it might discard the maximum should it have mid_1 and mid_2 in both the second part of the image above.
Or, on the example if a[mid_1] = 1 and a[mid_2] = 3, we will set the left pointer of the ternary search to mid_1+1, hence discarding the maximum.