# intersection of two arrays

```
1from bisect import bisect_left
2
3A = [1,2,3,5,8,9,7,5,4,3,3]
4B = [5,6,3,4,5,7,3,8,6,67]
5
6def intersect_two_arrays(A, B):
7 A.sort()
8 B.sort()
9 inter = []
10 for a in A:
11 index = bisect_left(B, a)
12 greater = index >= len(B)
13 smaller = index == 0 and a != A[index]
14 found = not (smaller or greater)
15 if found:
16 inter.append(a)
17 return inter
18
19r = intersect_two_arrays(A, B)
20print(r)
```