public static int[] searchRangeImproved(int[] A, int target) {
    int s = 0;
    int e = A.length;
    while(s < e){
      int mid = (s + e) / 2;
      if(A[mid] == target) {
        int ss = mid;
        int ee = mid;
        while(ss - 1 >= 0 && A[ss-1] == target)
          ss--;
        while(ee + 1 < A.length && A[ee+1] == target) 
          ee++;
        return new int[]{ss,ee};
      } else if(A[mid] < target){
        s = mid + 1;
      } else if(A[mid] > target){
        e = mid;
      }
    }
    return new int[] {-1,-1};
  }