This answer is very close but the groups must be given the lowest possible set of numbers.