- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1282.java
29 lines (27 loc) · 976 Bytes
/
_1282.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
packagecom.fishercoder.solutions.secondthousand;
importjava.util.ArrayList;
importjava.util.HashMap;
importjava.util.List;
importjava.util.Map;
publicclass_1282 {
publicstaticclassSolution1 {
publicList<List<Integer>> groupThePeople(int[] groupSizes) {
Map<Integer, List<Integer>> map = newHashMap<>();
for (inti = 0; i < groupSizes.length; i++) {
List<Integer> list = map.getOrDefault(groupSizes[i], newArrayList<>());
list.add(i);
map.put(groupSizes[i], list);
}
List<List<Integer>> result = newArrayList<>();
for (intkey : map.keySet()) {
List<Integer> list = map.get(key);
inti = 0;
do {
result.add(list.subList(i, i + key));
i += key;
} while (i + key <= list.size());
}
returnresult;
}
}
}