i cant find why my code is not accepted it is giving wrong anwser but it is stasifying all inputs

#include
#include <string.h>
#include <ctype.h>
using namespace std;

int main() 
{
	int t;
	cin>>t;
	while(t--)
	{
		char s[1002];
		cin>>s;
		int l=strlen(s);
		int i,j,k,flag=-1;
		if(l%2==0)
		{
			i=(l/2)-1;
			j=(l/2);
			while(i>=0 && j<l)
			{
				if(s[i]==s[j])
				{
					i--;
					j++;
					flag=1;
				}
				else
				{
					k=0;
					while(k<=i && j<l)
					{
						if(s[k]==s[j])
						{
							k++;
							j++;
							flag=1;
						}
						else
						{
							flag=0;
							break;
						}
					}
					i=-1;
					j=l;
				}
			}
		}
		else
		{
			flag=0;
			i=(l/2)-1;
			j=(l/2)+1;
			while(i>=0 && j<l)
			{
				if(s[i]==s[j])
				{
					i--;
					j++;
					flag=1;
				}
				else
				{
					flag=0;
					break;
				}
			}
			if(flag==0)
			{
				i=0;
				j=(l/2)+1;
				while(i<(l/2) && j<l)
				{
					if(s[i]==s[j])
					{
						i++;
						j++;
						flag=1;
					}
					else
					{
						flag=0;
						break;
					}
				}
			}
		}
		if(flag==1)
		cout<<"YES"<<endl;
		else if(flag==0)
		cout<<"NO"<<endl;
		
	}
	return 0;
}

Please give submission link + details about your logic instead of code.

Logic of your code is not correct the problem defines a “Lapindromes” as a string which have the same frequencies
of all the characters in the first half and second half of the string but in your solution you are comparing the
strings for examples
your code will give “YES” for TC
aabbcaabb
aabbcbbaa
But not for the test case
aabbcabab
although the frequency of a,b in first half and second half both are 2 so the answer should be “YES”
hope this helped :slight_smile:

1 Like

Ohh fuck i got it thank u so much i understand thanks for ur time

Welcome :slight_smile: