We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5284471 commit 50a1a9dCopy full SHA for 50a1a9d
anagram.py
@@ -0,0 +1,37 @@
1
+# https://www.hackerrank.com/challenges/anagram/problem
2
+
3
+ # old logic.
4
5
+ #!/bin/python3
6
7
+import sys
8
+from collections import defaultdict
9
10
11
+def anagram(s):
12
+ size = len(s)
13
+ if size % 2 == 1:
14
+ return -1
15
+ mydict = defaultdict(int)
16
+ for i in range(size//2):
17
+ item = s[i]
18
+ mydict[item]+=1
19
+ for i in range(size//2,size):
20
21
+ mydict[item]-=1
22
+ count = 0
23
+ for item in mydict.values():
24
+ count += abs(item)
25
+ return count//2
26
27
28
29
30
+q = int(input().strip())
31
+for a0 in range(q):
32
+ s = input().strip()
33
+ result = anagram(s)
34
+ print(result)
35
36
37
0 commit comments