-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommonCharactersCount.py
More file actions
38 lines (29 loc) · 927 Bytes
/
commonCharactersCount.py
File metadata and controls
38 lines (29 loc) · 927 Bytes
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
32
33
34
35
36
37
38
# Given two strings, find the number of common characters between them.
# Example
# For s1 = "aabcc" and s2 = "adcaa", the output should be
# solution(s1, s2) = 3.
def commonCharactersCount(s1, s2):
res = 0
for el in s1:
if el in s2:
s2 = s2.replace(el, "", 1)
res += 1
return res
# This function was added to get minimum difference to make words in lists anagrams.
def getMinimumDifference(a, b):
# Write your code here
res = []
if len(a) != len(b):
return "lists are different size"
for i in range(0, len(a)):
if len(a[i]) != len(b[i]):
res.append(-1)
else:
temp = commonCharactersCount(a[i], b[i])
res.append(len(a[i]) - temp)
return res
# Test case
a = ['a', 'jk', 'abb', 'mn', 'abc']
b = ['bb', 'kj', 'bbc', 'op', 'def']
if __name__ == "__main__":
print(getMinimumDifference(a, b))