subject

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

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 16:30
How to do this programming flowchart?
Answers: 3
question
Computers and Technology, 23.06.2019 17:10
Ac++an of of pi. in , pi is by : pi = 4 – 4/3 + 4/5 – 4/7 + 4/9 - 4/11 + 4/13 - 4/15 + 4/17 . ., to pi (9 ). , if 5 to pi,be as : pi = 4 - 4/3 + 4/5 - 4/7 + 4/9 = 4 – 1. + 0.8 - 0. + 0. = 3.. atoofbe to pi?
Answers: 2
question
Computers and Technology, 23.06.2019 21:00
Alcohol’s affects on the cornea and lens of the eye make it more difficult
Answers: 1
question
Computers and Technology, 24.06.2019 00:10
Read each statement below. if the statement describes a peer-to-peer network, put a p next to it. if the statement describes a server-based network, put an s next to it. p - peer-to-peer s - server-based
Answers: 1
You know the right answer?
You are given an array of arrays a. Your task is to group the arrays a[i] by their mean values, so t...
Questions
question
Computers and Technology, 19.09.2019 03:30
Questions on the website: 13722361