public int findKth(int[] a, int n, int K) {
        // write code here
        return find(a,0,n-1,K);
    }

    private int find(int[] a, int start, int end, int k) {
        if(start==end) return a[start];
        int index = partion(a,start,end);
        int len=a.length;
        int tar=len-k;
        if(tar==index) return a[index];
        else if(tar<index) return find(a,start,index-1,k);
        else return find(a,index+1,end,k);
    }

    private int partion(int[] a, int start, int end) {
        int temp=a[start];
        int i=start;
        int j=end;
        while (i<j){
            while (i<j && a[j]>=temp){
                j--;
            }
            a[i]=a[j];
            while (i<j && a[i]<temp){
                i++;
            }
            a[j]=a[i];
        }
        a[i]=temp;
        return i;
    }