Lapindromes - CodeChef Solution

Hello coders, today we are going to solve Lapindromes CodeChef Solution whose Problem Code is LAPIN. Lapindrome is defined as a string which when spli

Hello coders, today we are going to solve Lapindromes CodeChef Solution whose Problem Code is LAPIN.

Lapindromes - CodeChef Solution
👊 Table Of Contents

Task

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, abccab, rotor 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

Example

Sample Input

6
gaga
abcde
rotor
xyzxy
abbaab
ababc

Sample Output

YES
NO
YES
YES
NO
NO

Solution - Lapindromes - CodeChef Solution 

Python 3 

#Solution Provided by Sloth Coders 
T = int(input())
for i in range(T):
    n = input()
    l = len(n)
    if l % 2 == 0:
        b, c = n[:l//2], n[l//2:]
    else:
        b, c = n[:l//2], n[l//2+1:]
    if sorted(b) == sorted(c):
        print("YES")
    else:
        print("NO")

Disclaimer: The above Problem (Lapindromes) is generated by CodeChef but the Solution is provided by Sloth Coders. This tutorial is only for Educational and Learning Purpose.

Also Read:

Sloth Coders is a Learning Platform for Coders, Programmers and Developers to learn from the basics to advance of Coding of different langauges(python, Java, Javascript and many more).

Post a Comment