Lapindromes LAPIN - CodeChef Solution

Lapindromes LAPIN - CodeChef Solution
Lapindromes LAPIN - CodeChef Solution

Problem

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

Input :

6
gaga
abcde
rotor
xyzxy
abbaab
ababc

Output :

YES
NO
YES
YES
NO
NO


Solution:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'''
Algorithm for Lapindromes
    1. Taking input in a variable named “s”.
    2. Partitioning s into two halves s1,s2 (if odd no. of characters then to ignore the middle character).
    3. Storing in a list named l1, l2 and sorting them in ascending order.
    4. Converting it into the string and checking if the two halves are the same or not.
'''
# Lapindromes LAPIN - CodeChef Solution START
num = int(input())
s1 = ""
s2 = ""
for i in range(num):
    s =input()
    l = len(s)
    mid = int(l / 2)
    if(l%2==0):
        s1 = s[:mid]
        s2 = s[mid:]
    else:
        s1 = s[:mid]
        s2 = s[mid+1:]
    l1 = list(s1)
    l2 = list(s2)
    l1.sort()
    l2.sort()

    if(l1==l2):
        print("YES")
    else:
        print("NO")
# Lapindromes LAPIN - CodeChef Solution END



Disclaimer :-
the above information is display you by codeworld19 authority. The above information is taken on the basis of various materials so each of reference link provide are not possible, so if any of the query regarding this post or website fill the following contact form thank you.


Next Post Previous Post
No Comment
Add Comment
comment url