import java.util.*;

public class Solution {
    public int findKth(int[] a, int n, int K) {
        // write code here
        quickSort(a, 0, n - 1, n - K);
        return a[n - K];
    }
    private void quickSort(int[] arr, int start, int end, int index){
        if(start < end){
            int i = start;
            int j = end;
            int standard = arr[start];

            while(i < j) {
                while(arr[j] >= standard && i < j) j--;
                while(arr[i] <= standard && i < j) i++;
                if(i < j){
                    int temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }

            arr[start] = arr[i];
            arr[i] = standard;
            if(index == j) return;
            quickSort(arr, start, j - 1, index);
            quickSort(arr, j + 1, end, index);
        }
    }

}