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
[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

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 23:00
What is one of the main problems that can occur when implementing a large number of new systems within an organization?
Answers: 1
question
Computers and Technology, 22.06.2019 12:10
Linux is distributed under gnu gpl. why is this important? a. it ensures that only torvalds can profit from the sale of linux b. it prevents unknowledgeable users from downloading programs they don't know how to operate. c. it provides protection for the developers who created linux. d. it states that anyone can copy, modify, and share the program if changes are made public.
Answers: 1
question
Computers and Technology, 22.06.2019 17:00
What allows you to create a wireless connection among your smart devices
Answers: 2
question
Computers and Technology, 23.06.2019 01:40
You have a linux system that has a 1000gb hard disk drive, which has a 90gb partition containing an ext4 filesystem mounted to the / directory and a 4gb swap partition. currently, this linux system is only used by a few users for storing small files; however, the department manager wants to upgrade this system and use it to run a database application that will be used by 100 users. the database application and the associated data will take up over 200gb of hard disk space. in addition, these 100 users will store their personal files on the hard disk of the system. each user must have a maximum of 5gb of storage space. the department manager has made it very clear that this system must not exhibit any downtime as a result of hard disk errors. how much hard disk space will you require, and what partitions would you need to ensure that the system will perform as needed? where would these partitions be mounted? what quotas would you implement? what commands would you need to run and what entries to /etc/fstab would you need to create? justify your answers.
Answers: 3
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
Mathematics, 28.07.2019 02:30
question
English, 28.07.2019 02:30
Questions on the website: 13722362