Google Interview Questions – round 3

 

  • You have given an array. Find the maximum and minimum numbers in less number of comparisons.

    Solution:
    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.

  • You have given an array from 1 to N and numbers also from 1 to N. But more than one number is missing and some numbers have repeated more than once. Find the algo with running time O(n).

    Solution:All the numbers are positive to start with.Now, For each A[i], Check the sign of A[A[i]]. Make A[A[i]] negative if it’s positive. Report a repetition if it’s negative.Finally all those entries i,for which A[i] is negative are present and those i for which A[i] is positive are absent.

  • Tags: , ,


    Did You Enjoy This Post?

    Subscribe to our blog through our RSS feed or email to receive updates on more posts like this.post on your favourite social networking or media site to let others know about this post. Help us generate more buzz by submitting/voting for this post with the following buttons.

    Leave a Reply











    request new questions/article: send email to freequestionbank at gmail dot com