public static int FindKtht(int[] A, int aoffset, int m, int[] B, int boffset, int n, int k)
    {
        //Keep the A is the shorter array.
        if (m > n) FindKtht(B, boffset, n, A, aoffset, m, k);

        int[] temp;
        if (m == 0) return B[k - 1];
        if (k == 1) 
        	{
        		if(boffset==B.length)
        		{boffset--;}
        		return Math.min(A[aoffset], B[boffset]);
        	}

        //set pa and pb pointer
        int pa = Math.min(k / 2, m);
        int pb = k - pa;

        System.out.println(A[aoffset + pa - 1]);
        System.out.println(B[boffset + pb - 1]);
        
        if (A[aoffset + pa - 1] < B[boffset + pb - 1]) 
        	return FindKtht(A, aoffset + pa, m - pa, B, boffset, n, k - pa);

        return FindKtht(A, aoffset, m, B, boffset + pb, n - pb, k - pb);
    }