solution to find kth element