Efficient java solution

public ArrayList searchRange(final List a, int x) {

int first = getFirstOccurence(a,x);
int last =  getLastOccurence(a,x);
ArrayList<Integer> arrayList = new ArrayList<Integer>();
arrayList.add(first);
arrayList.add(last);
return arrayList;
}


int getFirstOccurence(List<Integer> a, int x){
    
    int start = 0;
    int pos =-1;
    int end = a.size()-1;
    while(start <= end){
        int mid = (start+end)/2;
        if(a.get(mid) == x){
            pos = mid;
            end=mid-1;
        }else if(x>a.get(mid)){
            start =  mid+1;
        }else{
            end = mid-1;
        }
       
    }
     return pos;
    
}




int getLastOccurence(List<Integer> a, int x){
    
    int start = 0;
    int pos =-1;
    int end = a.size()-1;
    while(start <= end){
        int mid = (start+end)/2;
        if(a.get(mid) == x){
            pos = mid;
            start=mid+1;
        }else if(x>a.get(mid)){
            start =  mid+1;
        }else{
            end = mid-1;
        }
        
    }
    return pos;

}

}

Click here to start solving coding interview questions