You are given an array A of size N. The array contains almost distinct elements with some duplicated. You have to print the elements in sorted order which appears more than once. 
Input Format:
The first line of input contains T, denoting the number of testcases. T testcases follow. Each testcase contains two lines of input.  The first line of input contains size of array N. The second line contains N integers separated by spaces.
Output Format:
For each test case, in a new line, print the required answer. If there are no duplicates print -1.
Your Task:
Your task is to complete the function SortedDuplicates(arr, n) which accepts array and its size as an argument. 
Constraints:
1 <= T <= 100
1 <= N <= 100
1 <= A_{i} <= 10^{6}
Examples:
Input:
1
9
3 4 5 7 8 1 2 1 3
Output:
1 3

Difficulty: EASY
Tags: Data structures
Skill types: Data structures

Starter code:


from typing import List





class Solution:

    def SortedDuplicates(self, n : int, arr : List[int]) -> None:

        # code here

        



Solutions:
from typing import List
from collections import Counter

class Solution:

	def SortedDuplicates(self, n: int, arr: List[int]) -> None:
		l = []
		a = Counter(arr)
		for i in range(len(arr)):
			if a[arr[i]] > 1:
				l.append(arr[i])
		s = set(l)
		b = list(s)
		b.sort()
		if len(b) >= 1:
			for j in range(len(b)):
				print(b[j], end=' ')
			print()
		else:
			print(-1)


from typing import List

class Solution:

	def SortedDuplicates(self, n: int, arr: List[int]) -> None:
		output = set()
		setti = set()
		for item in arr:
			if item in setti:
				output.add(item)
			setti.add(item)
		if not output:
			print(-1, end='')
		for item in sorted(output):
			print(item, end=' ')
		print()


from typing import List

class Solution:

	def SortedDuplicates(self, n: int, arr: List[int]) -> None:
		out = []
		dict = {}
		for i in arr:
			if dict.get(i) == None:
				dict.update({i: 1})
			else:
				out.append(i)
		out = list(set(out))
		out.sort()
		if len(out) == 0:
			print(-1)
		else:
			out = map(str, out)
			print(' '.join(out))


from typing import List

class Solution:

	def SortedDuplicates(self, n: int, arr: List[int]) -> None:
		freq = {}
		for i in range(n):
			if arr[i] in freq:
				freq[arr[i]] += 1
			else:
				freq[arr[i]] = 1
		duplicates = []
		for key in sorted(freq):
			if freq[key] > 1:
				duplicates.append(key)
		if len(duplicates) == 0:
			print('-1')
		else:
			print(' '.join((str(x) for x in duplicates)))


from typing import List

class Solution:

	def SortedDuplicates(self, n: int, arr: List[int]) -> None:
		l = []
		t = []
		for i in arr:
			if i not in l:
				l.append(i)
			else:
				t.append(i)
		if t == []:
			print(-1, end=' ')
		else:
			t = list(set(t))
			t.sort()
			for i in t:
				print(i, end=' ')
		print(' ')


from typing import List

class Solution:

	def SortedDuplicates(self, n: int, nums: List[int]) -> None:
		ans = []
		k = 0
		temp = [-1] * (max(nums) + 1)
		for i in nums:
			try:
				if temp[i] == 0:
					ans.append(i)
					temp[i] = 1
				elif temp[i] == -1:
					temp[i] = 0
			except:
				print(i)
		if len(ans) == 0:
			print(-1)
			return
		ans.sort()
		for j in ans[:-1]:
			print(j, end=' ')
		print(ans[-1])


from typing import List
from collections import Counter

class Solution:

	def SortedDuplicates(self, n: int, arr: List[int]) -> None:
		store = Counter(arr)
		a = []
		for i in store:
			if store[i] > 1:
				a.append(i)
		a.sort()
		if len(a) > 0:
			print(*a)
		else:
			print(-1)


from typing import List

class Solution:

	def SortedDuplicates(self, n: int, arr: List[int]) -> None:
		from collections import Counter
		l = Counter(arr)
		a = []
		for i in l.keys():
			if l[i] > 1:
				a.append(i)
		if len(a) > 0:
			a.sort()
			IntArray.Print(self, a)
		else:
			b = [-1]
			IntArray.Print(self, b)


from typing import List

class Solution:

	def SortedDuplicates(self, n: int, arr: List[int]) -> None:
		lst = arr.copy()
		a = set(lst)
		lst1 = list(a)
		lst2 = []
		dup = []
		if len(lst1) == len(arr):
			print(-1)
		else:
			for i in arr:
				if i not in lst2:
					lst2.append(i)
				else:
					dup.append(i)
			dup = list(set(dup))
			dup.sort()
			print(*dup)
			return


from typing import List

class Solution:

	def SortedDuplicates(self, n: int, arr: List[int]) -> None:
		from collections import Counter
		obj = Counter(arr)
		if max(obj.values()) == 1:
			print(-1)
		else:
			ans = []
			for i in obj:
				if obj[i] > 1:
					ans.append(i)
			ans.sort()
			ans = str(ans).replace(',', '')
			ans = str(ans).replace('[', '')
			ans = str(ans).replace(']', '')
			print(ans)


from typing import List

class Solution:

	def SortedDuplicates(self, n: int, arr: List[int]) -> None:
		hal = []
		dup = []
		j = 0
		while j < n + 1:
			hal.append([])
			j += 1
		for i in range(n):
			cur = arr[i] % (n + 1)
			if len(hal[cur]) == 0:
				hal[cur].append(arr[i])
			else:
				for k in range(len(hal[cur])):
					if hal[cur][k] == arr[i]:
						dup.append(arr[i])
						break
					elif k == len(hal[cur]) - 1:
						hal[cur].append(arr[i])
		if len(dup) == 0:
			print('-1')
		else:
			ret = list(set(dup))
			ret.sort()
			print(*ret)
		return


from typing import List
from collections import Counter

class Solution:

	def SortedDuplicates(self, n: int, arr: List[int]) -> None:
		freq = Counter(arr)
		lst = [key for (key, val) in freq.items() if val > 1]
		lst.sort()
		if len(lst) < 1:
			print('-1')
		else:
			for i in range(len(lst)):
				print(lst[i], end=' ')
			print()


from typing import List

class Solution:

	def SortedDuplicates(self, n: int, arr: List[int]) -> None:
		if len(arr) == len(set(arr)):
			print(-1)
		else:
			for i in sorted(list(set(arr))):
				if arr.count(i) > 1:
					print(i, end=' ')
			print()


from typing import List

class Solution:

	def SortedDuplicates(self, n: int, arr: List[int]) -> None:
		d = {}
		for i in sorted(set(arr)):
			d[i] = arr.count(i)
		x = False
		for i in sorted(d):
			if d[i] > 1:
				x = True
				print(i, end=' ')
		if x == False:
			print('-1')
		else:
			print()


from typing import List

class Solution:

	def SortedDuplicates(self, n: int, arr: List[int]) -> None:
		hmap = {}
		ans = []
		for i in arr:
			if i not in hmap:
				hmap[i] = 1
			else:
				hmap[i] += 1
		for (k, v) in hmap.items():
			if v > 1:
				ans.append(k)
		ans = sorted(ans)
		y = ' '.join([str(i) for i in ans])
		if ans != []:
			print(y)
		else:
			print(-1)


from typing import List

class Solution:

	def SortedDuplicates(self, n: int, arr: List[int]) -> None:
		d = {}
		for i in arr:
			if i not in d:
				d[i] = 1
			else:
				d[i] += 1
		l = []
		for i in d.keys():
			if d[i] > 1:
				l.append(i)
		a = sorted(l)
		b = IntArray()
		if len(l) >= 1:
			b.Print(a)
		else:
			print(-1)


from typing import List

class Solution:

	def SortedDuplicates(self, n: int, arr: List[int]) -> None:
		ans = []
		dcto = {}
		for x in arr:
			if x in dcto:
				dcto[x] += 1
			else:
				dcto[x] = 1
		for x in dcto:
			if dcto[x] > 1:
				ans.append(x)
		ans.sort()
		if len(ans) == 0:
			return print(-1)
		else:
			[print(i, end=' ') for i in ans]
			print()


from typing import List

class Solution:

	def SortedDuplicates(self, n: int, arr: List[int]) -> None:
		s = {}
		l = []
		for i in arr:
			if i in s:
				if s[i] == 1:
					l.append(i)
				s[i] += 1
			else:
				s[i] = 1
		l.sort()
		if len(l) == 0:
			print('-1')
		else:
			print(*l)


from typing import List

class Solution:

	def SortedDuplicates(self, n: int, arr: List[int]) -> None:
		d = {}
		for i in arr:
			if i not in d:
				d[i] = 1
			else:
				d[i] += 1
		ans = []
		for i in d:
			if d[i] > 1:
				ans.append(i)
		if len(ans) == 0:
			print(-1)
		else:
			ans = sorted(ans)
			print(*ans)


from typing import List

class Solution:

	def SortedDuplicates(self, n: int, arr: List[int]) -> None:
		lists = []
		dicts = {}
		for x in arr:
			if x in dicts:
				lists.append(x)
			else:
				dicts[x] = 1
		if len(lists) == 0:
			print(-1, end='')
		j = list(set(lists))
		j.sort()
		print(*j)


from typing import List

class Solution:

	def SortedDuplicates(self, n: int, arr: List[int]) -> None:
		l1 = []
		d1 = {}
		for i in arr:
			if i not in d1:
				d1[i] = 1
			else:
				d1[i] += 1
		for i in d1:
			if d1[i] > 1:
				l1.append(i)
		l1.sort()
		if len(l1) > 0:
			for i in l1:
				print(i, end=' ')
			print('')
		else:
			print(-1)


from typing import List

class Solution:

	def SortedDuplicates(self, n: int, arr: List[int]) -> None:
		l1 = []
		d1 = {}
		for i in arr:
			if i not in d1:
				d1[i] = 1
			else:
				d1[i] += 1
		for i in d1:
			if d1[i] > 1:
				l1.append(i)
		l1.sort()
		if len(l1) > 0:
			for i in l1:
				print(i, end=' ')
			print('')
		else:
			print(-1)

class IntArray:

	def __init__(self) -> None:
		pass

	def Input(self, n):
		arr = [int(i) for i in input().strip().split()]
		return arr

	def Print(self, arr):
		for i in arr:
			print(i, end=' ')
		print()
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input())
		arr = IntArray().Input(n)
		obj = Solution()
		obj.SortedDuplicates(n, arr)


from typing import List

class Solution:

	def SortedDuplicates(self, n: int, arr: List[int]) -> None:
		m = {}
		res = []
		f = 0
		for i in arr:
			if i in m:
				m[i] += 1
			else:
				m[i] = 1
		for (i, v) in m.items():
			if v > 1:
				f = 1
				res.append(i)
		if f == 0:
			print('-1')
			return
		res.sort()
		for i in res:
			print(i, end=' ')
		print()