Finding the length of the longest Palindromic Sub-String

Given a String , you have to find the sub-strings which are palindrome & get the maximum length of the longest sub-string that is palindrome.


For Example:
If the Given String is "abcmalayalamkfk", the possible sub-strings are "malayalam" & "kfk" having length of 14 & 3 respectively. Finally have to print the maximum length among the palindrome sub-strings.
So, the answer is "14"



Method 1:

1. Two variables, one pointing to beginning of the character array and another pointing the last character of the array.
 2. If the characters of the two pointers equals, left pointer increments and right pointer decrements 
3. If the characters doesn't matches, left pointer increments & right pointer doesn't changed. 
4. Steps 3 & 4 are repeated until the left pointer is less than right pointer. 
5. Every time, if there is a match, get the length by adding value '2' to the length. 
6. Update the maximum length every time, using conditional operator or writing GetMax function.

Implementation:


#include <stdio.h>
#define MAX 10000
int main()
{
    int T;
    char str[MAX],ctr;
    scanf("%d",&T);
    while(T--)
    {
     scanf("%s",&str);
  int len=strlen(str);
  int r=len-1;
  int l=0;
  int curl;
  int max=0;
  while(l<r)
  {
   if(str[l]!=str[r])
   {
    l++;
   }
   else
   {
    l++;
    r--;
    max=max+2;
   }
  }
  if(max==0)
  printf("%d\n",max);
  else
  printf("%d\n",max+1);
    }
    return 0;
}