-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathMissing Numbers.py
50 lines (40 loc) · 1.22 KB
/
Missing Numbers.py
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
39
40
41
42
43
44
45
46
47
48
49
50
"""
Problem Statement
Numeros, The Artist, had two lists A and B, such that, B was a permutation of A. Numeros was very proud of these lists.
Unfortunately, while transporting them from one exhibition to another, some numbers from List A got left out. Can you
find out the numbers missing from A?
"""
__author__ = 'Danyang'
class Solution(object):
def solve(self, cipher):
"""
:param cipher: the cipher
"""
m, A, n, B = cipher
result = set() # {} is for dictionary
hm = {}
for a in A:
if a not in hm:
hm[a] = 1
else:
hm[a] += 1
for b in B:
if b not in hm or hm[b] <= 0:
result.add(b)
else:
hm[b] -= 1
result = sorted(list(result))
return " ".join(map(str, result))
if __name__ == "__main__":
import sys
f = open("1.in", "r")
# f = sys.stdin
solution = Solution()
m = int(f.readline().strip())
A = map(int, f.readline().strip().split(' '))
n = int(f.readline().strip())
B = map(int, f.readline().strip().split(' '))
cipher = m, A, n, B
# solve
s = "%s\n" % (solution.solve(cipher))
print s,