I need to write a function that gets an array of numbers $a$ as an input and returns an index $i$ such that $a[i]<a[i+1]$ if it exists, if such $i$ doesn't exist return $-1$. (return any index $i$ if there are multiple).
We know that: in $a$ there are at least $2$ elements, $a$ may or may not be sorted and the first element in $a$ is less than the last element.
The solution needs to have $O(\log n)$ time-complexity and $O(1)$ space-complexity.
Example $a=[0,-8,-8,6,1]$, the function returns $2$ because $a[2]<a[3]$.
My Thoughts:
I need to somehow "split" the problem in half by cutting half of the numbers that I need to check in order to reach the required time complexity.
The array isn't ordered, but I have information that the first element is less than the last, and that there are at least two elements, so I need to somehow use this extra info.
The unsorted information is not allowing me to reach anything, I can definitely start from the middle and check if it's less than the last element, if yes then an index $i$ that satisfies $a[i]<a[i+1]$, will surely appear on the right side, but I can't just jump over half of the numbers to the right, they're unsorted, so the index $i$ might be the next one from the middle.