Write a function that merges two sorted arrays into a single one. The arrays only contain integers. Also, the final outcome must be sorted and not have any duplicate.

Difficulty: EASY
Tags: Fundamentals

Data structures
Skill types: Data structures

Starter code:
def merge_arrays(first, second):
	

Solutions:
def merge_arrays(a, b):
	return sorted(set(a + b))


def merge_arrays(first, second):
	return sorted(set(first + second))


def merge_arrays(first, second):
	working = []
	for e in first:
		if e not in working:
			working.append(e)
	for i in second:
		if i not in working:
			working.append(i)
	return sorted(working)


def update_if_new(d, results, element):
	if element not in d:
		results.append(element)
		d[element] = True

def merge_arrays(first, second):
	seen = dict()
	results = []
	(i, j, m, n) = (0, 0, len(first), len(second))
	while i < m and j < n:
		(x, y) = (first[i], second[j])
		if x < y:
			update_if_new(seen, results, x)
			i += 1
		else:
			update_if_new(seen, results, y)
			j += 1
	for residual in first[i:] + second[j:]:
		update_if_new(seen, results, residual)
	return results


def merge_arrays(first, second):
	result = list(set(first + second))
	result.sort()
	return result


def merge_arrays(first, second):
	first.extend(second)
	x = list(set(first))
	x.sort()
	return x


def merge_arrays(first, second):
	first = first + second
	a = set(first)
	third = []
	for y in a:
		third.append(y)
	return sorted(third)


def merge_arrays(first, second):
	bound = 0
	first = list(dict.fromkeys(first))
	second = list(dict.fromkeys(second))
	for indexB in range(len(second)):
		for indexA in range(bound, len(first)):
			if second[indexB] in first:
				break
			elif second[indexB] < first[indexA]:
				first.insert(indexA, second[indexB])
				bound += 1
				break
			elif indexA == len(first) - 1 and second[indexB] > first[indexA]:
				first.insert(indexA + 1, second[indexB])
	return first


def merge_arrays(first, second):
	first += second
	return list(sorted(set(first), reverse=False))


from functools import reduce
from operator import or_

def merge_arrays(*args):
	return sorted(reduce(or_, map(set, args)))


def merge_arrays(*a):
	result = []
	for sublist in a:
		for element in sublist:
			if not element in result:
				result.append(element)
	return sorted(result)


def merge_arrays(f, s):
	a = set(f + s)
	return sorted(a)


merge_arrays = lambda a, b: sorted(set(a + b))


def merge_arrays(arr1, arr2):
	merged = []
	(i, k) = (0, 0)
	while i < len(arr1) and k < len(arr2):
		(left, right) = (arr1[i], arr2[k])
		if left <= right:
			merged.append(left)
			i += 1
		else:
			merged.append(right)
			k += 1
	merged.extend(arr1[i:] if i < len(arr1) else arr2[k:])
	merged = list(dict.fromkeys(merged))
	return merged


merge_arrays = lambda f, g: sorted(set(f + g))


from typing import List

def merge_arrays(first: List[int], second: List[int]):
	return sorted(set(first + second))


def merge_arrays(first, second):
	new_list = first + second
	new_list.sort()
	return list(dict.fromkeys(new_list))


def merge_arrays(first, second):
	newlist = list(set(first + second))
	newlist.sort()
	return newlist


def merge_arrays(first, second):
	res = first + second
	res = list(dict.fromkeys(res))
	res.sort()
	return res


def merge_arrays(first, second):
	return sorted(list(set(first).union(set(second))))


def merge_arrays(first, second):
	l = []
	for n in first:
		if n not in l:
			l.append(n)
	for n in second:
		if n not in l:
			l.append(n)
	return sorted(l)


def merge_arrays(first, second):
	first.extend(second)
	x = list(dict.fromkeys(first))
	x.sort()
	return x


def merge_arrays(first, second):
	first.extend(second)
	first = list(set(first))
	return sorted(first)


def merge_arrays(first, second):
	x = []
	for i in range(0, len(first)):
		if first[i] not in x:
			x.append(first[i])
	for i in range(0, len(second)):
		if second[i] not in x:
			x.append(second[i])
	return sorted(x)


def merge_arrays(first, second):
	unique = []
	for f in first:
		if f not in unique:
			unique.append(f)
	for s in second:
		if s not in unique:
			unique.append(s)
	return sorted(unique)


def merge_arrays(first, second):
	ans = first + second
	ans.sort()
	unique = []
	for i in ans:
		if i not in unique:
			unique.append(i)
	return unique


def merge_arrays(first, second):
	i = 0
	j = 0
	print(first, second)
	common = []
	output = []
	if first == second and first == []:
		return []
	if first == []:
		return second
	if second == []:
		return first
	while i < len(first) and j < len(second):
		if first[i] < second[j]:
			common.append(first[i])
			i = i + 1
		elif first[i] == second[j]:
			common.append(first[i])
			i = i + 1
			j = j + 1
		elif first[i] > second[j]:
			common.append(second[j])
			j = j + 1
	if i < len(first):
		for k in range(i, len(first)):
			common.append(first[k])
	if j < len(second):
		for k in range(j, len(second)):
			common.append(second[k])
	output = [common[0]]
	k = 0
	for i in range(1, len(common)):
		if output[k] != common[i]:
			output.append(common[i])
			k = k + 1
	return output


def merge_arrays(first, second):
	if isinstance(first, dict) or isinstance(second, dict):
		return sorted(dict(dict.fromkeys(list(first.keys()) + list(second.keys()))))
	return sorted(dict(dict.fromkeys(first + second)))


import numpy as np

def merge_arrays(first, second):
	return sorted(set(first + second))


def merge_arrays(first, second):
	(merge, all) = ([], first + second)
	for n in all:
		if n not in merge:
			merge.append(n)
	return sorted(merge)


def merge_arrays(first, second):
	array = sorted(first + second)
	array_num = [0]
	for i in array:
		if i != array_num[-1]:
			array_num.append(i)
		else:
			pass
	array_num.remove(0)
	return array_num


def merge_arrays(first, second):
	cool = list(set(first + second))
	cool.sort()
	return cool


merge_arrays = lambda arr1, arr2: sorted(set(arr1 + arr2))


def merge_arrays(first, second):
	mylist = first + second
	return sorted(list(dict.fromkeys(mylist)))


def merge_arrays(first, second):
	a = list(dict.fromkeys(first + second).keys())
	a.sort()
	return a


def merge_arrays(first, second):
	for i in second:
		if i not in first:
			first.append(i)
	return sorted(list(set(sorted(first))))


def merge_arrays(first, second):
	third = set(first + second)
	return sorted(list(third))


def merge_arrays(first, second):
	s = first + second
	s.sort()
	l = []
	for i in s:
		if i not in l:
			l.append(i)
	return l


def merge_arrays(first, second):
	th = first + second
	th = list(set(th))
	th.sort()
	return th


def merge_arrays(first, second):
	bigboy = []
	for x in second:
		if x not in bigboy:
			bigboy.append(x)
	for x in first:
		if x not in bigboy:
			bigboy.append(x)
	bigboy.sort()
	return bigboy


from itertools import groupby

def merge_arrays(first, second):
	arr = first + second
	arr.sort()
	res = [i for (i, j) in groupby(arr)]
	return res


def merge_arrays(first, second):
	M = list(set(first + second))
	M.sort()
	return M


def merge_arrays(first, second):
	x = sorted(first + second)
	return list(dict.fromkeys(x))


def merge_arrays(f, s):
	x = list(set(f) | set(s))
	return sorted(x)
	pass


def merge_arrays(first, second):
	combined = set(first + second)
	return sorted(list(combined))


def merge_arrays(first, second):
	a = set(first)
	b = set(second)
	return sorted(list(a | b))


def merge_arrays(first, second):
	st = set(first + second)
	return sorted(list(st))


def merge_arrays(a, b):
	return sorted(set(a + b))
merge_arrays([2, 4, 8], [2, 4, 6])


def merge_arrays(first, second):
	first = first + second
	res = []
	for i in first:
		if i not in res:
			res.append(i)
	return sorted(res)


def merge_arrays(first, second):
	x = []
	for i in range(len(first)):
		x.append(first[i])
	for j in range(len(second)):
		x.append(second[j])
	y = []
	for z in range(len(x)):
		if x[z] in y:
			y = y
		else:
			y.append(x[z])
	return sorted(y)


def merge_arrays(arr1, arr2):
	for i in arr2:
		arr1.append(i)
	return sorted(set(arr1))


def merge_arrays(first, second):
	first.extend(second)
	sett = set(first)
	arr = list(sett)
	arr.sort()
	return arr


def merge_arrays(first, second):
	arr = first + second
	arr1 = []
	for i in arr:
		if i not in arr1:
			arr1.append(i)
	return sorted(arr1)


def merge_arrays(f, s):
	t = f + s
	res = sorted(t)
	res = set(res)
	return list(sorted(res))


def merge_arrays(a, b):
	a.extend(b)
	return sorted(list(set(a)))


def merge_arrays(first, second):
	hashing = set()
	for i in first:
		hashing.add(i)
	for j in second:
		hashing.add(j)
	return sorted(list(hashing))


def merge_arrays(first, second):
	a = []
	for i in first:
		if i not in a:
			a.append(i)
	for i in second:
		if i not in a:
			a.append(i)
	a.sort()
	return a


def merge_arrays(first, second):
	final = first + second
	final.sort()
	return list(dict.fromkeys(final))


def merge_arrays(first, second):
	test = list(set(first + second))
	test.sort()
	return test


def merge_arrays(first, second):
	new_arr = list(set(first + second))
	new_arr.sort()
	return new_arr


def merge_arrays(first, second):
	first.extend(second)
	res = list(set(first))
	res.sort()
	return res


import numpy as np

def merge_arrays(first, second):
	return sorted(np.unique(first + second))


def merge_arrays(first, second):
	result = sorted(first + second)
	i = 0
	while i <= len(result) - 2:
		if result[i] == result[i + 1]:
			del result[i]
		else:
			i = i + 1
	return result


def merge_arrays(first, second):
	final = set()
	for i in first:
		final.update(first)
		final.update(second)
	return sorted(final)


def merge_arrays(first, second):
	c = []
	for x in first:
		c.append(x)
	for x in second:
		c.append(x)
	return sorted(set(c))


def merge_arrays(first, second):
	x = first + second
	y = []
	for i in x:
		if i in y:
			continue
		else:
			y.append(i)
	y.sort()
	return y


def merge_arrays(first, second):
	m_tup = set(first + second)
	n_tup = list(m_tup)
	n_tup.sort()
	return n_tup


def merge_arrays(first, second):
	newlist = []
	for eachvalue in first:
		if eachvalue not in newlist:
			newlist.append(eachvalue)
	for eachvalue in second:
		if eachvalue not in newlist:
			newlist.append(eachvalue)
	return sorted(newlist)


def merge_arrays(first, second):
	concat_list = sorted(list(set(first + second)))
	return concat_list


def merge_arrays(arr1, arr2):
	res = []
	(i, k) = (0, 0)
	while i < len(arr1) or k < len(arr2):
		left = arr1[i] if i < len(arr1) else float('inf')
		right = arr2[k] if k < len(arr2) else float('inf')
		if left <= right:
			res.append(left) if not res or res[-1] != left else None
			i += 1
		else:
			res.append(right) if not res or res[-1] != right else None
			k += 1
	return res


def merge_arrays(first, second):
	first_set = set(first)
	second_set = set(second)
	inter = first_set.intersection(second_set)
	unio = first_set.union(second_set)
	my_list = list(unio)
	return sorted(my_list)


def merge_arrays(first, second):
	a = first + second
	res = []
	for x in a:
		if x not in res:
			res.append(x)
	return sorted(res)


def merge_arrays(first, second):
	first.sort()
	second.sort()
	third = first + second
	ls = []
	for i in third:
		if i in ls:
			continue
		ls.append(i)
	ls.sort()
	return ls


def merge(array):
	mid = len(array)
	if mid > 1:
		left = merge(array[:mid // 2])
		right = merge(array[mid // 2:])
		array = []
		while len(left) != 0 and len(right) != 0:
			if left[0] < right[0]:
				array.append(left.pop(0))
			else:
				array.append(right.pop(0))
		if len(left) != 0:
			array.extend(left)
		elif len(right) != 0:
			array.extend(right)
	return array

def merge_arrays(first, second):
	return merge(list(set(first + second)))


def merge_arrays(first, second):
	nowa = first + second
	nowa = list(set(nowa))
	nowa.sort()
	return nowa


from numpy import unique

def merge_arrays(first, second):
	return sorted(unique(first + second))


def merge_arrays(first, second):
	for i in first:
		while first.count(i) > 1:
			first.remove(i)
	for i in second:
		if not i in first:
			first.append(i)
	first.sort()
	return first


def merge_arrays(first, second):
	m = [i for i in set(first + second)]
	return sorted(m)


def merge_arrays(first, second):
	pass
	l = []
	l1 = []
	while first != [] and second != []:
		if first[0] < second[0]:
			l.append(first[0])
			del first[0]
		elif second[0] < first[0]:
			l.append(second[0])
			del second[0]
		else:
			l.append(first[0])
			del first[0]
			del second[0]
	if first == []:
		l.extend(second)
	elif second == []:
		l.extend(first)
	for i in l:
		if i not in l1:
			l1.append(i)
	return l1