public static int findMagicIndex(int[] array, int i, int j){
        //Since the array is sorted, we can perform a binary search in log(n) time
        //WHAT about if elements are not distinct? If elements are not distinct, this
        //algorithm will not work. Instead we must iterate through each element and search
        //in O(n) time
        if(j < i || i < 0 || j >= array.length) return -1;
        int mid = (i+j)/2;
        if(array[mid] == mid) return mid;

        if(array[mid] < mid) return findMagicIndex(array, mid+1, j);
        else return findMagicIndex(array, i, mid-1);
    }