import java.util.*;
public class Solution {
public int findKth(int[] a, int n, int k) {
// write code here
return findK(a, 0, n - 1, k - 1);
}
public int findK(int[] a, int start, int end, int k){
if(start >= end){
return a[start];
}
int left = start, right = end;
int midV = a[left + (right - left)/2];
while(left <= right){
while(a[left] > midV){left++;}
while(a[right] < midV){right--;}
if(left <= right){
int temp = a[left];
a[left] = a[right];
a[right] = temp;
left++;
right--;
}
}
if(k <= right){
return findK(a, start, right, k);
}else if( k >= left){
return findK(a, left, end, k);
}else{
return a[k];
}
}
}