public static int[] SearchRange(int[] a, int t) {
    int start, mid, end;
    int[] res = new int[2];
    
    if (a.length==0) {
      res[0] = res[1] = -1;
      return res;
    }
    
    // search for the left bound
    start = 0;
    end = a.length - 1;
    while (start + 1 < end) {
      mid = start + (end - start)/2;
      if (a[mid] >= t) {
        end = mid;
      } else {
        start = mid;
      }
    }
    if (a[start] == t) {
      res[0] = start;
    } else if (a[end] == t) {
      res[0] = end;
    } else {
      res[0] = res[1] = -1;
      return res;
    }
    // search for the right bound
    start = 0;
    end = a.length -1;
    while (start + 1 < end) {
      mid = start + (end-start)/2;
      if(a[mid] <= t) {
        start = mid;
      } else {
        end = mid;
      }
    }
    if (a[end] == t) {
      res[1] = end;
    } else if (a[start] == t) {
      res[1] = start;
    } else {
      res[0] = res[1] = -1;
      return res;
    }
    return res;
  }