Skip to content

Commit 6ef1495

Browse files
authored
Create Array intersection.py
Commit
1 parent 3e88941 commit 6ef1495

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import sys
2+
3+
def intersections(arr1, n, arr2, m):
4+
for i in range(n) :
5+
for j in range(m) :
6+
if arr1[i] == arr2[j] :
7+
print(arr1[i], end = " ")
8+
arr2[j] = sys.maxsize
9+
break
10+
11+
def takeInput() :
12+
n = int(sys.stdin.readline().strip())
13+
if n == 0:
14+
return list(), 0
15+
arr = list(map(int, sys.stdin.readline().strip().split(" ")))
16+
return arr, n
17+
#main
18+
t = int(sys.stdin.readline().strip())
19+
while t > 0 :
20+
arr1, n = takeInput()
21+
arr2, m = takeInput()
22+
intersections(arr1, n, arr2, m)
23+
print()
24+
t -= 1

0 commit comments

Comments
 (0)