Getting TLE for O(logn) solution for Java

public class Solution {
// DO NOT MODIFY THE LIST
public ArrayList searchRange(final List a, int b) {

    int low=0;
    int high=a.size()-1;
    
    int mid=0;
    int flag=0;
    
    while(low<=high){
        mid=(low+high)/2;
        if(a.get(mid)==b){
            flag=1;
            break;
        }
        else if(a.get(mid)<b){
            low=mid+1;
        }
        else{
            high=mid-1;
        }
    }
    
    
     ArrayList<Integer> ans= new ArrayList<>();
     if(flag==0){
         ans.add(-1);
         ans.add(-1);
         return ans;
     }
     int start=mid;
    int end=mid;
   
    while(start>=0 && a.get(start)==b){
        start--;
    }
    while(end<a.size() && a.get(end)==b){
        end++;
    }
   
    ans.add(start+1);
    ans.add(end-1);
    
    return ans;
}

}

Click here to start solving coding interview questions