public int findKthSortedArrays(int A[], int sA, int B[], int sB, int k){
        int eA = A.length - 1;
        int eB = B.length - 1;
        if(eA - sA > eB - sB){
            return findKthSortedArrays(B, sB, A, sA, k);
        }
        if(sA > eA) return B[sB+k-1];
        if(k==1) return Math.min(A[sA],B[sB]); // if k == 1, i is alwasy 0
        int i  = Math.min(k/2, eA-sA+1); // # of elements A can contribute
        int j = k - i; // # of elements A can contribute
        int a = A[sA+i-1];
        int b = B[sB+j-1];

        if(a < b) return findKthSortedArrays(A, sA+i, B, sB, k-i); // still need k-i
        else if(a > b) return findKthSortedArrays(A, sA, B, sB+j, k-j); // still need k-j
        else return a;
    }