-
Notifications
You must be signed in to change notification settings - Fork 3
/
IntersectionofTwoArrays.py
39 lines (28 loc) · 1019 Bytes
/
IntersectionofTwoArrays.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
# You have been given two integer arrays/list(ARR1 and ARR2) of size N and M, respectively.
# You need to print their intersection;
# An intersection for this problem can be defined when both the arrays/lists contain a particular value or to put it in other words,
# when there is a common value that exists in both the arrays/lists.
import sys
def intersections(arr1, n, arr2, m) :
#Your code goes here
for i in range(len(arr1)):
for j in range(len(arr2)):
if arr1[i] == arr2[j]:
print(arr1[i], end=' ')
arr2[j] = -1 # arr2[j] = sys.maxsize
break
#Taking Input Using Fast I/O
def takeInput() :
n = int(sys.stdin.readline().strip())
if n == 0:
return list(), 0
arr = list(map(int, sys.stdin.readline().strip().split(" ")))
return arr, n
#main
t = int(sys.stdin.readline().strip())
while t > 0 :
arr1, n = takeInput()
arr2, m = takeInput()
intersections(arr1, n, arr2, m)
print()
t -= 1