public int kthElement(int arr[],int k){
        int low = 0;
        int high = arr.length-1;
        int pos =0;
        while(true){
            pos = quickSelect(arr,low,high);
            if(pos == (k+low)){
                return arr[pos];
            }
            if(pos > k + low){
                high = pos-1;
            }else{
                k = k - (pos - low + 1);
                low = pos+1;
            }
        }
    }
Kth largest element in an array.
Use quickselect of quicksort to find the solution in hopefully O(nlogn) time.
Test cases
Sorted array
Reverse sorted array
src/com/interview/array/KthElementInArray.java