private int getk(int[] nums1, int l, int r, int[] nums2, int k) {
	    	if (k == 0) {
	    		if (nums1.length == 0)
	    			return nums2[0];
	    		else if (nums2.length == 0)
	    			return nums1[0];
	    		else
	    			return Math.min(nums1[0], nums2[0]);
	    	}
	    	if (l > r) {	// target not on nums1
	    		return getk(nums2, 0, nums2.length-1, nums1, k);
	    	} else {
	            int m = (l + r)/2;
	            // find idx of floor on nums2
	            int idx = binary(nums2, 0, nums2.length-1, nums1[m]);
	            int count = m + (idx + 1);  // handles if idx=-1, i.e., all nums2 >= nums1[k].
	            if (count == k)
	                return nums1[m];
	            int n = idx + 1;
	            while (n < nums2.length && nums2[n] == nums1[m]) {
	            	if (m + n + 1 == k) {
	            		return nums1[m];
	            	}
	            	n++;
	            }
	            if (count < k) // too few on left, move to right sub
	                return getk(nums1, m+1, r, nums2, k);
	            else // count > k, too many on left, move to left sub
	                return getk(nums1, l, m-1, nums2, k);
	        }
	    }