Can someone Explain whats wrong with the following code? I am getting TLE

public ArrayList<Integer> searchRange(final List<Integer> A, int B) {
    ArrayList<Integer> sol = new ArrayList<>();

    int low=0, high=A.size()-1;
    int mid = low + (high-low)/2;

    while(low<=high){
        mid = low + (high-low)/2;

        if(A.get(mid)==B && (mid==0 || A.get(mid-1)<B)){
            break;
        }
        else if(A.get(mid)==B){
            high = mid;
        }
        else if(A.get(mid)>B){
            high = mid-1;
        }
        else{
            low = mid+1;
        }
    }

    if(low>high){
        sol.add(-1);
        sol.add(-1);
        return sol;
    }

    sol.add(mid);

    low = mid;
    high = A.size();

    while(low<=high){
        mid = low + (high-low)/2;

        if(A.get(mid)==B && (mid==A.size()-1 || A.get(mid+1)>B)){
            break;
        }
        else if(A.get(mid)==B){
            low = mid;
        }
        else if(A.get(mid)>B){
            high = mid-1;
        }
        else{
            low = mid+1;
        }
    }

    sol.add(mid);

    return sol;
}
Click here to start solving coding interview questions