public static int findMedian(int[] s1, int []s2, int start1, int end1, int start2, int end2) {

        if(start1 <= end1 && start2 <= end2) {
            if(start1 +1 == end1 && start2 +1 == end2) {

                return (Math.max(s1[start1], s2[start2]) + Math.min(s1[end1], s2[end2])) /2;
            } else {

                int median1 = (end1 + start1)/2;
                int median2 = (end2 + start2)/2;

                if(s1[median1] == s2[median2]) {
                    return s1[median1];
                } else if(s1[median1] < s2[median2]) {
                    return findMedian(s1, s2, median1, end1, start2, median2);
                } else {
                    return findMedian(s1, s2, start1, median1, median2, end2);
                }
            }

        } else {
            return -1;
        }

    }