I faced a question in an interview two days back regarding optimally finding the maximum element in an array and I have query regarding that.
The array as described by interviewer consists of integer values which may repeat (not necessarily in consecutive places) and it also consists of two parts (One part may be empty) : First part in non-decreasing order, and second part in non-increasing order,i.e. if a[n] is an array consisting of n integer values, then, a[i]<=a[i+1],i in [1,m] and a[j]>=a[j+1],j in [m,n] and m lies somewhere between 1 and n inclusive. Now, they asked me to find the maximum value in the array in most efficient way.
I argued that as some elements may be repeated, I cannot element a search space using divide and conquer strategy. Had all the elements been distinct, we would be able to find maximum in lg n time using binary search. But there exists at least one input sequence (possibly when all elements are same) for which we at least need to have n-1 comparison before we can tell which element is maximum.
The interviewer asked me to think if I can impose some restriction on the input so that the problem can be solved in lg n time. I was not able to solve at that time and still thinking.
It would be helpful if you can help me in thinking.