Skip to content

Instantly share code, notes, and snippets.

@gauravkoradiya
Last active April 19, 2020 09:55
Show Gist options
  • Save gauravkoradiya/4f7dbe5fcc027482855036697e8efb05 to your computer and use it in GitHub Desktop.
Save gauravkoradiya/4f7dbe5fcc027482855036697e8efb05 to your computer and use it in GitHub Desktop.
Codechef_DSA01 - Lapindromes - Problem Code: LAPIN
"""https://www.codechef.com/LRNDSA01/problems/LAPIN"""
def LRNDSA01(ip,first_end,second_start,strlen):
d = dict()
for i in range(first_end):
d[ip[i]] = d.get(ip[i],0)+1
for j in range(second_start,strlen):
try:
d[ip[j]] = d[ip[j]] - 1
except:
return str("NO")
if any(d.values()) is True :
return str("NO")
else:
return str("YES")
def main():
n = int(input())
while (n != 0) :
ip = input()
strlen = len(ip)
if (strlen % 2) == 0:
first_end = int(strlen/2)
second_start = int(strlen/2)
result = LRNDSA01(ip=ip,first_end=first_end,second_start=second_start,strlen=strlen)
print(result)
else :
first_end = strlen//2
second_start = strlen//2 + 1
result = LRNDSA01(ip,first_end,second_start,strlen)
print(result)
n-=1
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment