New o(n^2) solution


#1

int n =S.length(), fi = 0, fj = 0, i,j,k;
for(i=0;i<n;i++)
{
j = i-1;
k = i+1;
while(j>=0 && k<n)
{
if(S[j] != S[k])
break;
j–;
k++;

        }
         if( k-j-1 > fj-fi+1)
               {
                   fi = j+1;
                   fj = k-1;
               }
        if( i<n-1 && S[i] == S[i+1])
        {
            j = i-1;
            k = i+2;
              while(j>=0 && k<n)
                {
                    if(S[j] != S[k])
                       break;
                       j--;
                       k++;
                       
                }
             if( k-j-1 > fj-fi+1)
               {
                   fi = j+1;
                   fj = k-1;
               }
        }
    }
    return S.substr(fi, fj-fi+1);