n participants numbered from 0 to n - 1. Each of them said in advance what team size they want: sizes[i] is the team size participant i asked for.
The organizer forms teams with a simple rule. Everyone who asked for a team of size k lines up by increasing number; the first k people in the line make one team, the next k make another, and so on.
Return the list of all teams, each as a list of its members' numbers. The order of the teams and the order of numbers inside a team do not matter.
The input guarantees that for every size k, the number of people who asked for it is a multiple of k, so everyone ends up on a team.sizes=[2, 1, 2, 3, 3, 3] → [[0, 2], [1], [3, 4, 5]]
Participant 1 wants to work alone: team [1]. Participants 0 and 2 form the pair, and 3, 4, 5 form the trio.
sizes=[2, 2, 2, 2] → [[0, 1], [2, 3]]
Everyone wants a pair. Going by number: first [0, 1], then [2, 3]. The answer [[0, 2], [1, 3]] is wrong because it breaks the queue rule.
sizes=[1] → [[0]]
k, the number of participants with sizes[i] = k is a multiple of ksizes=[2, 1, 2, 3, 3, 3]
[[0, 2], [1], [3, 4, 5]]
Run checks the first 3 tests in your browser. Submit checks all 41 tests on the server, hidden ones included.