I was looking for method to find efficient way to check if a string is rotated palindrome or not and apart from O(n^2) solution I found SO post which talks of O(n) solution which seems quite complex. I have written below code and I think it achieves the solution in O(n) as well in a much simpler hash table format.Can someone have a look at it and see if I am missing something here or my solution is correct ?
/*Code doesnt cover scenarios where character is caps and space*/
int main(void)
{
char str[] = "123217898";
char *pstr = str;
int length = strlen(str);
int notdouble = 0;
int arr[256] = { 0 };
for (int i = 0; i < length; i++)
{
arr[*pstr]++;
pstr++;
}
pstr = str;
for (int i = 0; i < length; i++)
{
/*check if its divisible by 2 and greater than 2*/
if (arr[*pstr] % 2 != 0 && arr[*pstr] > 2)
{
notdouble = 5; // just assign random value greater than 1
}
if (arr[*pstr] == 1)
{
notdouble++;
}
pstr++;
}
if (notdouble > 1)
{
printf("string is not palindrome \n");
}
else
{
printf("string is palindrome \n");
}
return 0;
}