
If Batch = { { 1, 2, 3, 4, 5 }, { 4, 2, 4 }, { 2, 3, 4 }, { 1, 1, 1, 1 }, { 0, 2 } }
Then:
Batch [ 0 ] = { 1, 2, 3, 4, 5 } has mean equal to ( 1 + 2 + 3 + 4 + 5 ) / 5 = 3
Batch [ 1 ] = { 4, 2, 4 } has mean equal to 3.33
Batch [ 2 ] = { 1, 1, 1, 1 } has mean equal to 1
Batch [ 3 ] = { 2, 3, 4 } has mean equal to 3
Batch [ 4 ] = { 0, 2 } has mean equal to 1
We will group Batch[0] and Batch[3] together, Batch[2] and Batch[4] together and Batch[1] will be grouped alone.
So we will finally return { { 0, 3 }, { 1 }, { 2, 4 } }.
(Note that we sorted the batch numbers inside each group, and then sorted all the groups by the first batch number inside each of them)
The first line contains a single integer ‘T’ denoting the number of test cases, then each test case follows:
The first line of each test case contains a single integer ‘N’ denoting the number of batches.
The next line contains N integers, where M[i] denotes the number of students in the ith batch.
The next N lines each contains M[i] integers, each denoting the ratings of the batch member.
For each test case, print all the groups, with each group containing batch numbers that are to be grouped together, all the groups are printed in a separate line.
Output for each test case will be printed in a separate line.
You are not required to print anything; it has already been taken care of. Just implement the function.
1 <= T <= 10
1 <= N <= 200
1 <= M <= 100
0 <= Batch[i][j] <= 10^6
Time limit: 1 sec
Create a hash-map with the key of type ‘double’ and value of type ‘array’. For each batch calculate its mean value and insert the batch number corresponding to its mean in the hash-map.
Finally, make an array of arrays, and iterate through the hash-map and insert each array corresponding to the value in hash-map into the array of arrays (insert each array after sorting it). In the end. Finally, sort the array of arrays and return it.
The steps are as follows :