This is an interview question There is an array of integers. The elements in the array can follow the following patterns.
What is the efficient way to find the max number in the array?
In that case, all you need to do is to determine whether it's (3). If not, the answer is max(first, last).
In the case that all elements are equal, you'll need to exhaustively search the array to show that there's not one high number somewhere in the middle. So I think it's O(n) to determine whether you're in (3).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With