public int search(int A[], int target) {
        int start = 0;
        int end = A.length - 1;
        
        while (start < end) {
            int mid = (start + end) / 2;
            
            if (A[mid] == target)
                return mid;
            if ((A[start] <= target && target < A[mid]) || (A[mid] < A[end] && (target < A[mid] || A[end] < target)))
                end = mid -1;
            else
                start = mid + 1;
        }
        
        if (A[start] == target)
            return start;
        return -1;
    }