Computers and Technology, 19.10.2020 22:01 PerfectMagZ
You are given an array of arrays a. Your task is to group the arrays a[i] by their mean values, so that arrays with equal mean values are in the same group, and arrays with different mean values are in different groups.
Each group should contain a set of indices (i, j, etc), such that the corresponding arrays (a[i], a[j], etc) all have the same mean. Return the set of groups as an array of arrays, where the indices within each group are sorted in ascending order, and the groups are sorted in ascending order of their minimum element.
Example
For
a = [[3, 3, 4, 2],
[4, 4],
[4, 0, 3, 3],
[2, 3],
[3, 3, 3]]
the output should be
meanGroups(a) = [[0, 4],
[1],
[2, 3]]
mean(a[0]) = (3 + 3 + 4 + 2) / 4 = 3;
mean(a[1]) = (4 + 4) / 2 = 4;
mean(a[2]) = (4 + 0 + 3 + 3) / 4 = 2.5;
mean(a[3]) = (2 + 3) / 2 = 2.5;
mean(a[4]) = (3 + 3 + 3) / 3 = 3.
There are three groups of means: those with mean 2.5, 3, and 4. And they form the following groups:
Arrays with indices 0and 4 form a group with mean 3;
Array with index 1 forms a group with mean 4;
Arrays with indices 2and 3 form a group with mean 2.5.
Note that neither
meanGroups(a) = [[0, 4],
[2, 3],
[1]]
nor
meanGroups(a) = [[0, 4],
[1],
[3, 2]]
will be considered as a correct
In the first case, the minimal element in the array at index 2 is 1, and it is less then the minimal element in the array at index 1, which is 2.
In the second case, the array at index 2 is not sorted in ascending order.
For
a = [[-5, 2, 3],
[0, 0],
[0],
[-100, 100]]
the output should be
meanGroups(a) = [[0, 1, 2, 3]]
The mean values of all of the arrays are 0, so all of them are in the same group.
Input/Output
[execution time limit] 3 seconds (java)
[input] array. array. integer a
An array of arrays of integers.
Guaranteed constraints:
1 ≤ a. length ≤ 100,
1 ≤ a[i].length ≤ 100,
-100 ≤ a[i][j] ≤ 100.
[output] array. array. integer
An array of arrays, representing the groups of indices
Answers: 2
Computers and Technology, 22.06.2019 07:30
Events and conditions that happen within an organization that are somewhat easier to deal with when responding to change are called
Answers: 1
Computers and Technology, 23.06.2019 19:30
2. fluorine and chlorine molecules are blamed fora trapping the sun's energyob forming acid rainoc producing smogod destroying ozone molecules
Answers: 2
Computers and Technology, 23.06.2019 20:30
If chris has a car liability insurance, what damage would he be covered for
Answers: 1
Computers and Technology, 23.06.2019 22:30
What would be the address of the cell, which is at the intersection of the second row and the third column in a worksheet?
Answers: 1
You are given an array of arrays a. Your task is to group the arrays a[i] by their mean values, so t...
Mathematics, 18.09.2020 15:01
Mathematics, 18.09.2020 15:01
Mathematics, 18.09.2020 15:01
German, 18.09.2020 15:01
Mathematics, 18.09.2020 15:01
Mathematics, 18.09.2020 15:01
Biology, 18.09.2020 15:01
History, 18.09.2020 15:01
Mathematics, 18.09.2020 15:01
Mathematics, 18.09.2020 15:01
Mathematics, 18.09.2020 15:01
Mathematics, 18.09.2020 15:01
Physics, 18.09.2020 15:01
Mathematics, 18.09.2020 15:01
English, 18.09.2020 15:01
Mathematics, 18.09.2020 15:01
Mathematics, 18.09.2020 15:01
Mathematics, 18.09.2020 15:01
History, 18.09.2020 15:01
Social Studies, 18.09.2020 15:01