#K60017. Common Elements Across Sorted Arrays
Common Elements Across Sorted Arrays
Common Elements Across Sorted Arrays
You are given an integer T
representing the number of test cases. For each test case, you are given an integer K
representing the number of sorted arrays. Following this, for each of the K
arrays, the first line contains an integer N
indicating the number of elements in the array, and the next line contains N
space-separated integers sorted in non-decreasing order.
Your task is to find all unique common elements that appear in every one of the K
arrays. If there are common elements, print them in ascending order separated by a single space. If there are no common elements, output No common elements!
.
Note: The input is read from standard input (stdin) and the output should be written to standard output (stdout).
inputFormat
The first line of input contains an integer T
, the number of test cases. For each test case, the first line contains an integer K
representing the number of arrays. Then, for each of the K
arrays, the first line contains an integer N
(the size of the array) followed by a second line with N
space-separated integers in sorted order.
outputFormat
For each test case, print a single line containing the common elements in ascending order separated by a space. If there are no common elements, print No common elements!
.## sample
4
3
5
1 2 3 4 5
4
2 4 6 8
4
0 2 4 6
2
4
1 4 5 6
4
6 7 8 9
3
3
1 2 3
3
2 3 4
3
0 2 3
3
3
1 2 3
3
4 5 6
3
7 8 9
2 4
6
2 3
No common elements!
</p>