More DBA job interview questions and answers at
(Continued from previous question...)
Google Technical Interviews in Management round: You have given an array. Find the maximum and minimum numbers in less number of comparisons.
only 3n/2 comparisons are necessary to find both the minimum and the maximum. To do this, we maintain the minimum and maximum elements seen thus far. Rather than processing each element of the input by comparing it against the current minimum and maximum, however, at a cost of two comparisons per element, we process elements in pairs. We compare pairs of elements from the input first with each other, and then compare the smaller to the current minimum and the larger to the current maximum, at a cost of three comparisons for every two elements.
(Continued on next question...)