# Lapindromes: LAPIN

### Lapindromes Codechef Solution in C, C++, JAVA and Python

Lapindrome is defined as a string which when split in the middle, gives two halves having the same characters and same frequency of each character. If there are odd number of characters in the string, we ignore the middle character and check for lapindrome. For example gaga is a lapindrome, since the two halves ga and ga have the same characters with same frequency. Also, abccabrotor and xyzxy are a few examples of lapindromes. Note that abbaab is NOT a lapindrome. The two halves contain the same characters but their frequencies do not match.
Your task is simple. Given a string, you need to tell if it is a lapindrome.

### Input:

First line of input contains a single integer T, the number of test cases.
Each test is a single line containing a string S composed of only lowercase English alphabet.

### Output:

For each test case, output on a separate line: “YES” if the string is a lapindrome and “NO” if it is not.

### Constraints:

• 1 ≤ T ≤ 100
• 2 ≤ |S| ≤ 1000, where |S| denotes the length of S

6
gaga
abcde
rotor
xyzxy
abbaab
ababc

YES
NO
YES
YES
NO
NO

## Lapindromes Codechef Solution in C

#include &lt;stdio.h>

int main(void) {
int t,l,n,c;
char a&#91;1000];
scanf("%d",&amp;t);
while(t--)
{
scanf("%s",&amp;a);
c=0;
l=strlen(a);
if(l%2==0)
{
n=l/2;
}
else
n=l/2+1;
for(int i=0;i &lt; l/2;i++)
{
for(int j=n;j &lt; l;j++)
{
if(a&#91;i]==a&#91;j])
{
c++;
a&#91;j]=l/2;
break;
}
}
}
if(c==l/2)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}

## Lapindromes Codechef Solution in C++ 17

#include &lt;bits/stdc++.h>
using namespace std;

#define input_for(arr1, n)    \
for (int i = 0; i &lt; n; i++) \
cin >> arr1&#91;i]
#define output_for(arr1, n)   \
for (int i = 0; i &lt; n; i++) \
cout &lt;&lt; arr&#91;i] &lt;&lt; ' '
bool check_prime(int n)
{
bool is_prime = true;

if (n == 0 || n == 1)
{
is_prime = false;
}

for (int i = 2; i &lt;= n / 2; ++i)
{
if (n % i == 0)
{
is_prime = false;
break;
}
}

return is_prime;
}
void solve()
{
string s;
cin >> s;
int hash&#91;26] {0};
if (s.length() % 2 == 0)
{
for (int i = 0; i &lt; s.length() / 2; i++)
{
hash&#91;s&#91;i] - 97]++;
}
for (int i = s.length()/2; i &lt; s.length(); i++)
{
hash&#91;s&#91;i] - 97]--;
}
int flag = 0;
for (int i = 0; i &lt; 26; i++)
{
if (hash&#91;i] != 0)
flag = 1;
}
if (flag == 1)
cout &lt;&lt; "NO" &lt;&lt; endl;
else
cout &lt;&lt; "YES" &lt;&lt; endl;
}
else
{
for (int i = 0; i &lt; s.length() / 2; i++)
{
hash&#91;s&#91;i] - 97]++;
}
for (int i = s.length()/2+1; i &lt; s.length(); i++)
{
hash&#91;s&#91;i] - 97]--;
}
int flag = 0;
for (int i = 0; i &lt; 26; i++)
{
if (hash&#91;i] != 0)
flag = 1;
}
if (flag == 1)
cout &lt;&lt; "NO" &lt;&lt; endl;
else
cout &lt;&lt; "YES" &lt;&lt; endl;
}
}
int main()
{
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}

## Lapindromes Codechef Solution in Python 3

for _ in range(int(input())):
s=input()
n=len(s)
if n%2==0:
l=s[:n//2]
r=s[n//2:n]
else:
l=s[:n//2]
r=s[n//2+1:n]

if sorted(l)==sorted(r):
print("YES")
else:
print("NO")

## Lapindromes Codechef Solution in Java

import java.util.*;
import java.lang.*;
import java.io.*;
class lapindrome
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner kk=new Scanner(System.in);
int testcase=kk.nextInt();
kk.nextLine();
while(testcase-->0)
{
String s=kk.next();
int flag=0;
int n1,n2;
int n=s.length();
int[] a=new int[26];
int[] b=new int[26];
if(n%2==0)
n1=n/2;//6/2=3
else
n1=(n/2)+1;

for(int i=0;i < n/2;i++)
a[s.charAt(i)-97]++;
for(int i=n-1;i>=n1;i--)
b[s.charAt(i)-97]++;
for(int i=0;i < 26;i++)
{
if(a[i]!=b[i])
{
flag++;
break;
}
// System.out.println(a[i]+" "+b[i]);
}
if(flag==0)
System.out.println("YES");
else
System.out.println("NO");
}
}
}

This content is uploaded for study, general information, and reference purpose only.