Lapindrome WA

can someone plz tell me why my Lapindrome code gives a wrong answer…it is workng fine for the test cases mentioned in example

#include<stdio.h>
#include<string.h>
int lapindrome(char[]);
int main()
{
int cases=0,j=0,f=0;
char str[1000];
scanf("%d",&cases);
while(j<cases)
{
scanf("%s",str);
f=lapindrome(str);
if(f==0)
printf("NO\n");
else printf("YES\n");
j++;
}
return 0;
}
int lapindrome(char str[1000])
{
char arr[500];
int l=strlen(str),i,k;
for(i=0,k=0;i<l/2;i++,k++)
{
arr[k]=str[i];
}
if(l%2==0)
i=l/2;
else
i=l/2+1;
while(i<l)
{
for(k=0;k<l/2;k++)
{
if(str[i]==arr[k])
{
arr[k]='#';
break;
}
}
i++;
}
for(k=0;k<l/2;k++)
{
if(arr[k]!='#')
return 0;
}
return 1;
}

@phoenix25 >> Here is the AC version of your code. Just increased the array size. :stuck_out_tongue:

@phoenix25 Your implementation is correct. Mistake is in declaring str character array. Since length of str can go up to 1000, you will need 1001 size character array to store it, 1 extra character to store null character \0.

So change

char str[1000]; TO char str[1001]; and
char arr[500]; TO char arr[501];

Then you are good to go.

Have you disabled the link ? Cause it doesn’t seem to open in my browser.
Term paper writing service representative.

After clicking “Post your answer” I see someone(you :P) already answered question :slight_smile:

:smiley: I am sorry for that.