Alice is taking a cryptography class and finding anagrams to be very useful. We consider two strings to be anagrams of each other if the first string's letters can be rearranged to form the second string. In other words, both strings must contain the same exact letters in the same exact frequency For example, bacdc
and dcbac
are anagrams, but bacdc
and dcbad
are not.
Alice decides on an encryption scheme involving two large strings where encryption is dependent on the minimum number of character deletions required to make the two strings anagrams. Can you help her find this number?
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the makeAnagram function below.
def makeAnagram(a, b):
x1=[0]*26 ####
x2=[0]*26
for c in a:
j=ord(c)-ord('a') ####
x1[j]+=1
for c in b:
j=ord(c)-ord('a')
x2[j]+=1
result=sum(abs(x1[i]-x2[i]) for i in range(26))
return result
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
a = input()
b = input()
res = makeAnagram(a, b)
fptr.write(str(res) + '\n')
fptr.close()
.