Problem of the day
The first line contains an integer ‘T’ denoting the number of test cases. Then each test case follows.
The first input line of each test case contains an integer ‘N’ denoting the number of accounts.
Each of the next ‘N’ lines contains space-separated strings where the first string denotes the account holder’s name, and the rest of the strings represent the email addresses.
For each test case, print the number of accounts after merging in the first line and then print the space-separated name and email address associated with each account in a separate line.
Print the output of each test case in a separate line.
You are not required to print the expected output; it has already been taken care of. Just implement the function.
1 <= T <= 50
1 <= N <= 100
1 <= |accounts[i]| <= 10
1 <= |accounts[i][j]| <= 30
Time limit: 1 sec
2
4
Rahul rahul1@gmail.com rahul2@gmail.com
Amit amit1@gmail.com
Ankur ankur9773@yahoo.com
Rahul rahul1@gmail.com rahul1998@yahoo.com
2
John john2020@gmail.com
Marry mary@outlook.com
3
Rahul rahul1998@yahoo.com rahul1@gmail.com rahul2@gmail.com
Amit amit1@gmail.com
Ankur ankur9773@gmail.com
2
John john2020@gmail.com
Marry mary@outlook.com
For the first test case, the first and fourth Rahul’s are the same person as they have a shared email address “rahul1@gmail.com”. The rest of the accounts are of different persons as they don’t share any shared email addresses. So, we merge the first and fourth account.
For the second test case, none of the accounts shares any shared email address.
2
2
Atul atul@mail.com
Atul atul1@mail.com
1
Bhavani bhavani@mail.com
2
Atul atul1@mail.com
Atul atul@mail.com
1
Bhavani bhavani@mail.com
For the first test case, the first and second Atul are two different people since they don’t have any common email addresses.
For the second test case, there is only one account. So merging is not required.