public static List<List<Integer>> divideList(List<Integer> originalList, int numContainers) {
List<List<Integer>> dividedList = new ArrayList<>();
int elementsPerContainer = originalList.size() / numContainers;
int remainder = originalList.size() % numContainers;
int index = 0;
for (int i = 0; i < numContainers; i++) {
List<Integer> container = new ArrayList<>();
int count = elementsPerContainer + (i < remainder ? 1 : 0);
for (int j = 0; j < count; j++) {
container.add(originalList.get(index));
index++;
}
dividedList.add(container);
}
return dividedList;
}
07-07
3699
03-28
1312
09-06
288