public int needed(String a, int start, int end) {
    if (start < 0)
      return a.length() - end;
    if (end >= a.length())
      return start + 1;

    if (needref[start][end] != -1)
      return needref[start][end];

    if (a.charAt(start) != a.charAt(end)) {
      return needref[start][end] = (1 + Math.min(needed(a, start - 1, end),
          needed(a, start, end + 1)));
    } else
      return needref[start][end] = needed(a, start - 1, end + 1);
  }