kth to end element algorithm.