Hackerrank - Search - Missing Numbers
Numeros, the Artist, had two lists and , such that was a permutation of . Numeros was very proud of these lists. Unfortunately, while transporting them from one exhibition to another, some numbers were left out of . Can you find the missing numbers?
- If a number occurs multiple times in the lists, you must ensure that the frequency of that number in both lists is the same. If that is not the case, then it is also a missing number.
- You have to print all the missing numbers in ascending order.
- Print each missing number once, even if it is missing multiple times.
- The difference between maximum and minimum number in is less than or equal to .
Input Format
There will be four lines of input:
- the size of the first list
This is followed by space-separated integers that make up the first list.
- the size of the second list
This is followed by space-separated integers that make up the second list.
This is followed by space-separated integers that make up the first list.
- the size of the second list
This is followed by space-separated integers that make up the second list.
Output Format
Output the missing numbers in ascending order.
Sample Input
10 203 204 205 206 207 208 203 204 205 206 13 203 204 204 205 206 207 205 208 203 206 205 206 204
Sample Output
204 205 206
Explanation
is present in both arrays. Its frequency in is , while its frequency in is . Similarly, and occur twice in , but thrice in . So, these three numbers are our output. The rest of the numbers have thesame frequency in both lists.
Solution
# Enter your code here. Read input from STDIN. Print output to STDOUT
itt = int(raw_input())
A = map(int,raw_input().split())
itt_b = int(raw_input())
B = map(int,raw_input().split())
mini = min(B)
answer = []
lis = [0 for x in range(102)]
for k in A:
lis[k-mini] -= 1
for d in B:
lis[d-mini] += 1
for ind, ele in enumerate(lis):
if ele != 0:
answer.append(ind+mini)
print ' '.join(map(str,answer))
Comments
Post a Comment