Split into rooms: hints, no solution

Medium · Linked list

A conference organiser has a queue of attendee ids in arrival order and n breakout rooms. The queue is split into n consecutive parts, one per room, so that every attendee lands in exactly one room and order is kept. No two parts may differ in size by more than one, and any longer parts must come before the shorter ones.

With L attendees, that means each room gets L divided by n rounded down, and the first L mod n rooms get one extra. When there are more rooms than attendees, some parts are empty.

Return the n parts as an array of arrays, in room order. A linked-list version cuts the chain at the right nodes rather than copying values.

Examples

Input
queue = [1, 2, 3, 4, 5, 6, 7], rooms = 3
Output
[[1, 2, 3], [4, 5], [6, 7]]
Note
Seven attendees over three rooms gives sizes 3, 2 and 2.
Input
queue = [1, 2, 3], rooms = 5
Output
[[1], [2], [3], [], []]
Note
Three attendees fill three rooms with one each, and the last two rooms are empty.

Constraints

  • 0 <= queue.length <= 600
  • 1 <= rooms <= 450
  • 0 <= queue[i] <= 999

Hint 1: a nudge

Before moving anything, can you say how many attendees each room should get, using only the queue length and the room count?

Unlock the full hints and timed practice with a pass

The second and third hints and the timed, runner-checked practice are part of a pass.

See pricing

Sign in

Check my resume first