#337 Grouping Profiles by Organization and Group

Companies:
Lighthouse
Themes:
JavaStreams & LambdasPractice

Group the data so that the first Map uses organizationId as the key and contains another Map as its value, where groupId is the key and List<Profile> is the value:

static public class Profile {
        public Long id;
        public Long organizationId;
        public Long groupId;
}

public Map<Long, Map<Long, List<Profile>>> groupByOrgIdAndGroupId(List<Profile> data) {
    ...
}
Example:
[1, 0, 1]
[2, 0, 1]
[3, 0, 2]
[4, 1, 1]
[5, 1, 2]

Result:
{
    "0": {
        "1" : [{1..}, {2..}],
        "2" : [{3..}],
    }
    "1": {
        "1" : [{4..}],
        "2" : [{5..}]
    }
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in