public int getMedian(int a[], int aStart, int aEnd, int b[], int bStart,
            int bEnd, int k) {
        int aLength = aEnd - aStart + 1, bLength = bEnd - bStart + 1;
        if (aLength <= 0)
            return b[bStart + k];
        if (bLength <= 0)
            return a[aStart + k];
        if (k == 0)
            return a[aStart] < b[bStart] ? a[aStart] : b[bStart];

        // I don't understand this one
        int aMid = aLength * k / (aLength + bLength);
        int bMid = k - aMid - 1;

        aMid = aMid + aStart;
        bMid = bMid + bStart;

        if (a[aMid] > b[bMid]) {
            k = k - (bMid - bStart + 1);
            aEnd = aMid;
            bStart = bMid + 1;
        } else {
            k = k - (aMid - aStart + 1);
            bEnd = bMid;
            aStart = aMid + 1;
        }

        return getMedian(a, aStart, aEnd, b, bStart, bEnd, k);
    }