title: Remove only one element to make a string palindrome
body: <p>I will be given string. I can remove only 1 element from it. After removing it if the new string becomes palindrome I have to print "Yes" otherwise "No".</p>
  
  <p>For example, I am given a string "abdbca". Here I can remove 5th index 'c' and make it palindrome and i have to print "Yes". On the other hand if the string is something like "abcd" I can not make it palindrome by removing only one character. Hence I have to print "No".</p>
  
  <p>I tried to do it but my code is not efficient enough. Can anybody please suggest me a efficient way to do it? I have to check strings of 10^5 length in less than 2.5 seconds.</p>
  
  <p>the way I tried to do it is shown bellow : </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdio&gt;
  #include &lt;cstring&gt;
  #include &lt;string&gt;
  
  #define REP(i,n)    for(int i=0;i&lt;n;i++)
  #define MAX 100010
  
  using namespace std;
  
  bool isPalindrome(char abc[]){
      int len = strlen(abc), lem = len/2;
      for(int i=0,n=len-1;i&lt;=lem;i++,n--) if(abc[i]!=abc[n]) return false;
      return true;
  }
  
  int main()
  {
      int tc;
      char str[MAX];
      scanf("%d",&amp;tc);
      while(tc--){
          scanf("%s", str);
          int length = strlen(str), len = length - 1, z = length % 2, res = 0, ans = 0,         b=0,lem = length / 2;
          for(int i = 0;i&lt;length;i++){
              int n=0, m=1;
              for(int x = 0, y = len;x&lt;i &amp;&amp; y!=i;x++,y--){
                  n++;
                  if(str[x]!=str[y]){
                      m=0; ++res;
                      break;
                  }
              }
              if(i&gt;lem) for(int x=n,y=len-n-1;x&lt;y;x++,y--){
                  if(str[x]!=str[y]){
                      m=0; ++res;
                      break;
                  }
              }
              else for(int x=n+1,y=len-n;x&lt;y;x++,y--){
                  if(str[x]!=str[y]){
                      m=0; ++res;
                      break;
                  }
              }
              if(m==1) {printf("YES\n");b++;break;}
          }
          //if(length &lt;= res) printf("NO\n");
          if(b==0) printf("NO\n");
      }
      return 0;
  }
  </code></pre>