Given an array which is a sorted array of integers.
What is the fastest running time to find the maximum where
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
to get maximum of x - y, x must be the greatest element in the array, and y must be the smallest element.
because the array is already sorted, you only need the first and the last element of the array to get those elements.