Approach finding first and last occurrence of element


#1
    start=0
    end=len(A)-1
    res1=-1
    if len(A)==1:
        return [0,0]
    while(start<=end):
        mid=start+(end-start)//2
        if B==A[mid]:
            res1=mid
            end=mid-1
        else:
            if B<A[mid]:
                end=mid-1
            else:
                start=mid+1
    start=0
    end=len(A)-1
    res2=-1
    while(start<=end):
        mid=start+(end-start)//2
        if B==A[mid]:
            res2=mid
            start=mid+1
        else:
            if B<A[mid]:
                end=mid-1
            else:
                start=mid+1
    return[res1,res2]