Find distinct elements
Submissions: 3482   Accuracy:

22.89%

  Difficulty: Easy   Marks: 2

Given a N x N matrix. Write a program to find count of all the distinct elements common to all rows of the matrix. Print count of such elements.

Input:
First line of input contains a single integer T which denotes the number of test cases. T test cases follows. First line of each test case contains a single integer N which denotes the dimension of matrix. Second line of each test case contains N*N space separated integers which denotes elements of the matrix.

Output:
For each test case, print count of all the distinct elements common to all rows of the matrix.

Constraints:
1 <= T <= 100
1 <= N <= 1000

Example:
Input:

2
4
2 1 4 3 1 2 3 2 3 6 2 3 5 2 5 3
5
12 1 14 3 16 14 2 1 3 35 14 1 14 3 11 14 25 3 2 1 1 18 3 21 14

Output:
2
3

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Harsh Agarwal
Author: harsh.agarwal0


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.