forked from srishilesh/Data-Structure-and-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMissing_numbers
55 lines (44 loc) · 1.14 KB
/
Missing_numbers
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
51
52
53
54
55
// https://www.hackerrank.com/challenges/missing-numbers/problem
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the missingNumbers function below.
def missingNumbers(arr, brr):
original = {}
dup = {}
if(len(arr) == len(brr)):
return []
result = []
for i in brr:
if i in original:
original[i]+=1
else:
original[i] = 1
for i in arr:
if i in dup:
dup[i]+=1
else:
dup[i] = 1
for key,item in original.items():
if(key not in dup):
result.append(key)
else:
if(dup[key]!=item):
for i in range(abs(item-dup[key])):
result.append(key)
result = list(set(result))
result.sort()
return result
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input())
arr = list(map(int, input().rstrip().split()))
m = int(input())
brr = list(map(int, input().rstrip().split()))
result = missingNumbers(arr, brr)
fptr.write(' '.join(map(str, result)))
fptr.write('\n')
fptr.close()