Solution for Kth smallest element in array