Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6ef1495

Browse files
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
Lines changed: 24 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /