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 b7f8ad1

Browse files
author
Amogh Singhal
authored
Create union_arrays.py
1 parent 2736169 commit b7f8ad1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

‎union_arrays.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Problem: Given two sorted array of sizes m and n
2+
# in which all elements are distinct. Find the
3+
# union between them
4+
# Constraints: in O(m+n) complexity.
5+
6+
def unionArrays(x, y, m, n):
7+
union_arr = []
8+
9+
for i in range(m):
10+
union_arr.append(x[i])
11+
12+
for j in range(n):
13+
if y[j] not in union_arr:
14+
union_arr.append(y[j])
15+
16+
print(union_arr)
17+
return
18+
19+
list_a = [1, 2, 3, 4, 5]
20+
list_b = [2, 3, 5, 6]
21+
unionArrays(list_a, list_b, len(list_a), len(list_b))

0 commit comments

Comments
(0)

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