private int findKthValue(int A[], int firstA, int B[], int firstB, int k) {
			if (firstA >= A.length)
				return B[k - 1];

			if (firstB >= B.length)
				return A[k - 1];

			if (k == 1)
				return Math.min(A[firstA], B[firstB]);

			if (A.length > B.length)
				return findKthValue(B, firstB, A, firstA, k);

			int partA = Math.min(A.length, k / 2);
			int partB = k - partA;

			if (A[firstA + partA - 1] > B[firstB + partB - 1]) {
				return findKthValue(A, firstA, B, firstB + partB, k - partB);
			} else if (A[firstA + partA - 1] < B[firstB + partB - 1]) {
				return findKthValue(A, firstA + partA, B, firstB, k - partA);
			} else {
				return A[firstA + partA - 1];
			}
		}