public static double findKth(int A[], int B[], int initA, int endA, int initB, int endB, int k){
        int m = A.length;
        int n = B.length;
        int K = k + 1;
        if(m == 0){
            return B[initB + k];
        }
        if(n == 0){
            return A[initA + k];
        }
        if(K == 1){
            return A[initA] < B[initB] ? A[initA] : B[initB];
        }
        int aKth = initA + K/2 - 1 < A.length?(initA + K/2 -1): Integer.MAX_VALUE;
        int bKth = initB + K/2 - 1 < B.length?(initB + K/2 -1): Integer.MAX_VALUE;

        if(A[aKth] > B[bKth]){
            endA = aKth;
            initB = bKth;
            K = K - K/2;
        }
        if(A[aKth] < B[bKth]){
            initA = aKth;
            endB = bKth;
            K = K - K/2;
        }
        return findKth(A,B,initA,endA,initB,endB,K-1);
    }