Saturday, 7 September 2013

Find a element "k" such that there are "k" greater elements than this element in the unsorted array

Find a element "k" such that there are "k" greater elements than this
element in the unsorted array

Accolite Interview:
Input: Array of integers (no range given) , unsorted , size n
Output: Find a element "k" in the array, such that there are exactly "k"
elements in the array which are greater than this element.
For example if the array is :
1. [4,3,6,9,10,22] Output here is 4
2. [4,3,6,9,10] output: No such number found
This question can be done very easily by sorting in O(n log n) Time , but
i was asked to do it in O(n) time (and if O(logn) possible).

No comments:

Post a Comment